Simple and basic life-cycle and inheritance JS screwdriver.
use...
// viola, a class inheriting from Compoo
var Person = Compoo.extend({
constructor: function (name) {
this.name = name;
},
sayHi: function (personName) {
console.log("Yo, " + personName + "!");
}
});
var Dude = Person.extend({
sayHi: function (otherDude) {
// notice that you don't need to use Person.prototype
Person.sayHi.call(this);
console.log("You're the dude of " + otherDude);
}
});
Normal Compoo way - slower but more conventient from JS point of view:
var thisDude = Person.create();
Classical way with the new
keyword - faster but meh...:
var thatDude = new Person.constructor();
Extending Compoo via the api object will make Compoo and every derived object inherit the new feature.
Example:
Compoo.api.extend('getName', function () {
return this.name;
});
will result in:
var person = new Person.constructor('Jon');
person.getName(); // 'Jon'
person.implement(
{jsNinja: true},
{
likesJS: function () {
return true;
}
}
);
var otherPerson = person.clone({
name: 'Jacob'
});
var person = new Person.constructor();
person.is(Person); // true
person.is(Dude); // false
person.has('name');