npm.io
0.1.0 • Published 12 years ago

defjs

Licence
Version
0.1.0
Deps
0
Vulns
0
Weekly
0

def

def - A simple Ruby-style inheritance for JavaScript

Dependencies

ECMAScript 5: Object.create

Example

def ('Person') ({
    __init__: function (name) {
        this.name = name;
    },

    speak: function (text) {
        alert(text || 'Hi, my name is ' + this.name);
    }
});

def ('Friend') << Person ({
    kick: function () {
        this.speak("I kick u!");
    }
});

def ('Ninja') << Friend ({
    __init__: function (name) {
	    Friend.__init__(name)
    },

    kick: function () {
        this.speak('I kick u!');
    }
});

var ninjy = new Ninja("John");

ninjy.speak();
ninjy.kick();

Keywords