Skip to content Skip to sidebar Skip to footer

Combining Javascript Pseudo-class Objects Under A Single Namespace

I have some classes I ported from Java to JavaScript. I would like to combine them in a library. for example: var myLibrary = { version: 1.0, ...more code... }; Now a cla

Solution 1:

Use an IIFE

var myLibrary = (function(){

   var jTicker = function(length,spaces) {
    //make space evenif (spaces%2 != 0) { spaces += 1; }
    //set space size]this.spaceSize = spaces;
    //set lengththis.viewLength = length;
    //start positionthis.position = 0;
    this.key = 0;
    //all messagesthis.messages = {};
   }

   // you can have all your prototype code here herereturn{
      version:"1.0",
      jTicker:jTicker
   };

})();

usage

var myInstance = new myLibrary.jTicker(10,30);

Post a Comment for "Combining Javascript Pseudo-class Objects Under A Single Namespace"