Page 1 of 1
Anyone figured out scopes with inline JS functions?
Posted: Wed Jul 05, 2017 3:30 am
by tj1010
Example of the problem. Same with variable scope.
Code: Select all
Procedure ddd(text.s)
Debug text
EndProcedure
Procedure fff()
!function test(){
!f_ddd('1234');
!}
!test();
EndProcedure
fff()
Re: Anyone figured out scopes with inline JS functions?
Posted: Wed Jul 05, 2017 5:16 am
by PartTimeCoder
Its not a scope issue, SpiderBasic does not compile procedures that are not called in SB code so your example will not work, adding a call to the function makes SB compile the proc and it calls from JS, strange behaviour!!
Code: Select all
Procedure ddd(text.s)
Debug text
EndProcedure
Procedure fff()
!function test(){
!f_ddd('1234');
!}
!test();
EndProcedure
ddd("") ; force SB To compile!!
fff()
Re: Anyone figured out scopes with inline JS functions?
Posted: Wed Jul 05, 2017 1:55 pm
by tj1010
PartTimeCoder wrote:Its not a scope issue, SpiderBasic does not compile procedures that are not called in SB code so your example will not work, adding a call to the function makes SB compile the proc and it calls from JS, strange behaviour!!
Code: Select all
Procedure ddd(text.s)
Debug text
EndProcedure
Procedure fff()
!function test(){
!f_ddd('1234');
!}
!test();
EndProcedure
ddd("") ; force SB To compile!!
fff()
It's going to be a problem when people start using Cordova plugins, because even with the linker optimization bypassed and everything defined SB still uses a non-global scope and Cordova uses out of scope asynchronous callbacks.
Re: Anyone figured out scopes with inline JS functions?
Posted: Wed Jul 05, 2017 2:38 pm
by Peter
better this one (no unneed call of ddd()):
Code: Select all
If 1 = 2
ddd("") ; force SB To compile!!
EndIf
Greetings ... Peter