Different Javascript Errors

Just starting out? Need help? Post your questions and find answers here.
Stefan Schnell
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am
Contact:

Different Javascript Errors

Post 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
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Different Javascript Errors

Post 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.
Stefan Schnell
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am
Contact:

Re: Different Javascript Errors

Post by Stefan Schnell »

Hello Fred,

thanks for your reply, good to know.

Cheers
Stefan
Post Reply