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 [2019/01/11 19:07] – [Require vs. Load] Added comment about exit() use in libraries 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 =====  ===== exit ===== 
Line 16: Line 16:
  
 ==== 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 35: 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 ==== ==== Index ====
 Articles documenting the usage of specific JavaScript Libraries are listed here: Articles documenting the usage of specific JavaScript Libraries are listed here:
Line 45: Line 53:
 ===== See Also ===== ===== See Also =====
   * [[:custom:javascript:|JavaScript]]   * [[:custom:javascript:|JavaScript]]
-  * [[http://cvs.synchro.net/cgi-bin/viewcvs.cgi/exec/load/|load Directory contents from Synchronet CVS]]+  * [[https://gitlab.synchro.net/main/sbbs/-/tree/master/exec/load|load Directory contents from Synchronet Git Repo]]
  
 {{tag>javascript}} {{tag>javascript}}