Anyone figured out scopes with inline JS functions?

Just starting out? Need help? Post your questions and find answers here.
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Anyone figured out scopes with inline JS functions?

Post 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()
PartTimeCoder
Posts: 1
Joined: Wed Jul 05, 2017 5:10 am

Re: Anyone figured out scopes with inline JS functions?

Post 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()
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: Anyone figured out scopes with inline JS functions?

Post 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.
Last edited by tj1010 on Wed Jul 05, 2017 3:14 pm, edited 3 times in total.
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Anyone figured out scopes with inline JS functions?

Post by Peter »

better this one (no unneed call of ddd()):

Code: Select all

If 1 = 2
  ddd("") ; force SB To compile!!
EndIf
Greetings ... Peter
Post Reply