A dummy prototype inheritance tool for javascript.
Require the file and you are done:
var extendme = require('/path/to/extendme.js');
Simply include the extendme.js
file, it would add extendme
under window
namespace.
To create a type of object:
var Person = {
type: 'person'
, sayHi: function() {
return 'hello, dude';
}
};
var person = extendme.create(Person);
person.sayHi(); // 'hello, dude.'
To extend a type of object:
var Ninja = extendme.extend(Person, {
type: 'ninja'
, weapon: 'sword'
, attack: function() {
return 'whaaaaa!!!!';
}
});
var ninja = extendme.create(Ninja);
ninja.sayHi(); // 'hello dude.'
ninja.attack(); // 'whaaaaa!!!'
console.log(ninja.type); // 'ninja'
console.log(ninja.weapon); // 'sword'
That's it, ENJOY!!!