npm.io
0.1.6 • Published 12 years ago

strapjs

Licence
MIT
Version
0.1.6
Deps
0
Vulns
0
Weekly
3

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!"