strapjs

0.1.6 • Public • Published

strap.js

Documentation

Browser compatibility

This library is designed to be used in all modern browsers and Node.js.

Known issues

  • phantomjs not fully supported! At the moment some unit tests are failing (namespace loader) due to some strange errors with qunit and phantomjs

HelloWorld the simple way

// define the class
var Hello = class_({
 
    // constructor
    initialize: function(name) {
        this.name = name;
    },
 
    // method with your own logic
    output: function() {
        alert("Hello " + this.name + "!");
    }
 
});
 
// create instances of the the class
var instance1 = new Hello("World");
var instance2 = new Hello("strap.js");
 
// work with the instances
instance1.output(); // --> "Hello World!"
instance2.output(); // --> "Hello strap.js!"
 
// overwrite instance
instance1 = new Hello("Ninja");
instance1.output(); // --> "Hello Ninja!"

HelloWorld with namespaces

Class definition:

namespace_('strapjs.examples.helloworld', {
 
    HelloWorld: class_({
 
        // constructor
        initialize : function(name) {
            this.name = name;
        },
 
        // method with your own logic
        output : function() {
            alert("Hello " + this.name + "!");
        }
 
    })
});

Class usage:

// register the namespaces to use
var used = use_('strapjs.examples.helloworld');
 
// create an instance using the loader
var tst1 = used.create('HelloWorld', ['World!']);
 
// create an instance using the load with callback
var tst2 = used.create('HelloWorld', ['Dude!'], function(wrld2) {
    alert('callback ' + wrld2.name);
}); // --> "callback Dude!"
 
// create an instance without the loader but the whole namespace
var tst3 = new strapjs.examples.helloworld.HelloWorld('Ninja!');
 
// work with the instances
tst1.output(); // --> "Hello World!"
tst2.output(); // --> "Hello Dude!"
tst3.output(); // --> "Hello Ninja!"

Readme

Keywords

none

Package Sidebar

Install

npm i strapjs

Homepage

strapjs.org

Weekly Downloads

1

Version

0.1.6

License

MIT

Last publish

Collaborators

  • strapjs