Difference between revisions of "Namespace.js"

From LugdunonWiki
Jump to: navigation, search
(Created page with "At the core of Lugdunon is the '''''Namespace''''' object. This object provides for an object oriented model in JS, as well as runtime code/class dependency resolution. It als...")

Revision as of 17:28, 13 October 2013

At the core of Lugdunon is the Namespace object. This object provides for an object oriented model in JS, as well as runtime code/class dependency resolution. It also provides support for internationalization (i18n), asset loading, and local caching of assets.


Let’s take a look at what a simple class representing a 2dPoint (in net/lugdunon/math/TwoDPoint.js) would look like:


  1. Namespace.package("net.lugdunon.math");
  2. Namespace.newClass("net.lugdunon.math.TwoDPoint");
  3.  
  4. net.lugdunon.math.TwoDPoint.prototype.init=function(initData)
  5. {
  6.     this.x=initData.x;
  7.     this.y=initData.y;
  8.  
  9.     return(this);
  10. };
  11.  
  12. net.lugdunon.math.TwoDPoint.prototype.add=function(p)
  13. {
  14.     if(p.instanceOf && p.instanceOf("net.lugdunon.math.TwoDPoint"))
  15.     {
  16.         this.x+=p.x;
  17.         this.y+=p.y;
  18.     }
  19. };