Inline Javascript

Introduction

SpiderBasic allows you to include raw JavaScript directly into the source code. To activate the inline JavaScript input, you can use the compiler directives EnableJS and DisableJS. Another way is to put '!' (exclamation mark) at the beginning of the line, and the whole line will be put as is in the generated source.

Please note than the JavaScript code isn't checked by the SpiderBasic compiler, so if a syntax error occurs in this code, it will be reported in the browser when executing the code.

The IDE coloring can also be wrong sometimes with JavaScript input, but it won't impact the generated code.

Rules

Here are the naming rules to use when accessing SpiderBasic items: - JavaScript variable name is the same in lowercase with a 'v_' prefix. It's the same for local variable, global variable and function parameter.

Example

  MyVariable = 10
  !v_myvariable++;
  Debug MyVariable
- JavaScript pointer name is the same in lowercase with a 'p_' prefix. It's the same for local pointer, global pointer and function parameter.

Example

  *Pointer = 10
  !p_pointer = 20;
  Debug *Pointer
- JavaScript procedure name is the same in lowercase with a 'f_' prefix.

Example

  Procedure MyProcedure()
    Debug "Hello world"
  EndProcedure
  
  ; Call in SpiderBasic
  MyProcedure()
  
  ; Call using Javascript
  !f_myprocedure();
- JavaScript module name is the same in lowercase and using the '$' sign to access module items. Example
  DeclareModule MyModule
    MyModuleVariable.i
  EndDeclareModule
  
  Module MyModule
  EndModule
  
  !mymodule$v_mymodulevariable = 12
  Debug MyModule::MyModuleVariable

Example

InlinedJS.sb