Synchronet v3.19b-Win32 (install) has been released (Jan-2022).

You can donate to the Synchronet project using PayPal.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
custom:javascript:lib:index [2018/12/27 19:22] – Fill out the library usage examples more, fixed some typos digital mancustom:javascript:lib:index [2024/03/11 21:24] (current) – [See Also] Replace CVS link with GitLab link digital man
Line 8: Line 8:
  
 ===== Require vs. Load ===== ===== Require vs. Load =====
-The ''require()'' function (added in Synchronet v3.17) is identical in usage to ''load()'' with the exception that it will //conditionally// load and execute the script only if the property name argument (specified just after the filename argumentis not already defined in the target scope. This prevents redundant loading/compilation/execution of libraries shared among multiple modules. For large libraries or commonly used libraries, consider using ''require()'' instead of ''load()'' to enhance performance and avoid the possible erroneous redefinition of ''const'' variables during subsequent ''load()'' operations of the same library.+The ''require()'' function (added in Synchronet v3.17) is identical in usage to ''load()'' with the exception that it will //conditionally// load and execute the script only if the property name (''propname'') argument, specified just after the filename argumentis not already defined in the target scope. This prevents redundant loading/compilation/execution of libraries shared among multiple modules. For large libraries or commonly used libraries, consider using ''require()'' instead of ''load()'' to enhance performance and avoid the possible erroneous redefinition of ''const'' variables during subsequent ''load()'' operations of the same library.
  
 +===== exit ===== 
 +Libraries should **not** (normally) call the global ''exit()'' method or else the calling script(s) will also terminate, possibly unexpectedly.
 ===== Styles ===== ===== Styles =====
 There are 3 main //styles// of JavaScript libraries included with Synchronet: There are 3 main //styles// of JavaScript libraries included with Synchronet:
  
 ==== Legacy ==== ==== Legacy ====
-//Leagcy//-style JavaScript libraries just define a series of vars, consts or functions which may be referenced, as needed, by a loading script. Legacy-style libraries may be loaded into a distinct scope object or into the caller's global scope, whatever is most convenient for the application.+//Leagcy//-style JavaScript libraries just define a series of ''vars''''consts'' or ''functions'' which may be referenced, as needed, by a loading script. Legacy-style libraries may be loaded into a distinct scope object or into the caller's global scope, whatever is most convenient for the application.
  
 Example Legacy-style library usage: Example Legacy-style library usage:
-  load('somedefs.js'); +<code javascript> 
-  some_function(some_value);+load('somedefs.js'); 
 +some_function(some_value); 
 +</code>
  
 ==== Object ==== ==== Object ====
-//Object//-style JavaScript libraries define an object that can by instantiated (like a class, using the ''new'' keyword), as needed, by the loading script. You can identify Object-style libraries because they will typically define an object constructor function, some Object.prototype member functions (methods), and perhaps one or more Object.defineProperty() calls to define property //getters// and //setters//.+//Object//-style JavaScript libraries define an object that can by instantiated (like a class, using the ''new'' keyword), as needed, by the loading script. You can identify Object-style libraries because they will typically define an object constructor function, some ''Object.prototype'' member functions (methods), and perhaps one or more ''Object.defineProperty()'' calls to define property //getters// and //setters//.
  
 Example Object-style library usage: Example Object-style library usage:
-  load('someobject.js'); +<code javascript> 
-  var someObj = new SomeObject(); +load('someobject.js'); 
-  someObj.property = true; +var someObj = new SomeObject(); 
-  someObj.do_something();+someObj.property = true; 
 +someObj.do_something(); 
 +</code>
  
 ==== Return ==== ==== Return ====
Line 33: Line 39:
  
 Example Return-style library usage: Example Return-style library usage:
-  var someLib = load({}, 'somelib.js'); +<code javascript> 
-  someLib.property = true; +var someLib = load({}, 'somelib.js'); 
-  someLib.do_something();+someLib.property = true; 
 +someLib.do_something(); 
 +</code> 
 + 
 +Return-style libraries are the preferred style of [[person:digital man]], but all styles of JavaScript libraries may found within the Synchronet ''[[dir:exec]]/[[dir:load]]'' directory. 
 + 
 +==== Index ==== 
 +Articles documenting the usage of specific JavaScript Libraries are listed here: 
 +{{indexmenu>.}}
  
 ===== See Also ===== ===== See Also =====
   * [[:custom:javascript:|JavaScript]]   * [[:custom:javascript:|JavaScript]]
 +  * [[https://gitlab.synchro.net/main/sbbs/-/tree/master/exec/load|load Directory contents from Synchronet Git Repo]]
  
 {{tag>javascript}} {{tag>javascript}}