2.0.0 • Published 9 years ago

hr.class v2.0.0

Weekly downloads
41
License
-
Repository
github
Last release
9 years ago

hr.class Build Status

Base class and events manager

Installation

$ npm install hr.class

Documentation

Create a new class by extending the default Class:

var Class = require("hr.class");

var MyClass = Class.extend({
    // Default options
    defaults: {

    },

    // Constructor
    initialize: function() {

    }
});

Events

Class instances can emit events:

obj.trigger("myevent");
// obj.emit("myevent") is equivalent

// Sub-events
obj.trigger("myevent:subevent")

// With event property
obj.trigger("myevent", {
    myproperty: 1
});

Listening to event using .on:

obj.on("myevent", function(e) {
    // Will be called for "myevent" and "myevent:subevent"
});

listenTo can also be used to avoid memeory leaks in events listeners when an object is listening to another object:

obj1.listenTo(obj2, "myevent", function() {
    // this == obj1
});

Mixins

Class can be extended using mixins.

var MyMixin = Class.Mixin({
    myMethod: function() {
        ...
    }
});

var ChildClass = MyClass.mixim(
    MyMixin,
    AnotherMixin
)
.extend({

});
2.0.0

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago