hr.class

2.0.0 • Public • Published

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({

});

Readme

Keywords

none

Package Sidebar

Install

npm i hr.class

Weekly Downloads

7

Version

2.0.0

License

none

Last publish

Collaborators

  • samypesse