Page 1 of 1

Different Javascript Errors

Posted: Wed Dec 02, 2015 2:14 pm
by Stefan Schnell
Hello community,

I tried the following code to integrate JS functions inside SpiderBasic and it produces some errors (you can find the generated JS code as comments inside the source):
; Begin-----------------------------------------------------------------

; Function JSTest1----------------------------------------------------
Procedure.s JSTest1(Text.s)
Protected res.s
!v_res = window.btoa(v_Text);
ProcedureReturn res
EndProcedure

;function proc0(v_text) { //convert variable name to lower case
;var v_res="";
;v_res = window.btoa(v_Text);
;return v_res;
;return ""; //unreachable code
;}

; Function JSTest2----------------------------------------------------
Procedure JSTest2()
EnableJS
Return 42;
DisableJS
EndProcedure

;function proc2() {
;Return 42; //syntax error
;return 0; //unreachable code
;}

; Main----------------------------------------------------------------
Debug JSTest1("Stefan")
Debug JSTest2()

; End-------------------------------------------------------------------
Workaround for the variable names: Use only lower case variable names for this kind of using.
Suggestion for a future release of SpiderBasic: Don't convert variable names.

Suggestion for the EnableJS block: Disable automatic code correction (and syntax highlighting) in SpiderBasic IDE inside a EnableJS...DisableJS block.

Suggestion: Remove unreachable code automatically after the first return - not necessary but nice.

Cheers
Stefan

Re: Different Javascript Errors

Posted: Thu Dec 03, 2015 8:21 am
by Fred
As SB is case insensitive, but javascript isn't, we decided to convert all variable in lowercase in javascript. So you can use any case in SB, but if you want to access it in JS, it should be lowercase. Should work for any variable.

Re: Different Javascript Errors

Posted: Thu Dec 03, 2015 9:33 am
by Stefan Schnell
Hello Fred,

thanks for your reply, good to know.

Cheers
Stefan