Skip to content

Instantly share code, notes, and snippets.

@shekarsiri
Forked from k33g/kind.js
Created August 5, 2013 22:38
Show Gist options
  • Save shekarsiri/6160246 to your computer and use it in GitHub Desktop.
Save shekarsiri/6160246 to your computer and use it in GitHub Desktop.
// Just do this : (and include backbone.js)
var Kind = function() {
this.initialize && this.initialize.apply(this, arguments);
};
Kind.extend = Backbone.Model.extend
//Simpler
var Thing = function() {};
Thing.extend = Backbone.Model.extend
// Use it :
var Human = Kind.extend({
toString : function() { console.log("hello : ", this); },
initialize : function (name) {
console.log("human constructor");
this.name = name
}
});
//Someone inherits of Human
var SomeOne = Human.extend({
initialize : function(name){
//call parent constructor
SomeOne.__super__.initialize.call(this, name);
}
});
var Bob = new Human("Bob");
Bob.toString();
var Sam = new SomeOne("Sam");
Sam.toString();
// Use it :
var Human = Thing.extend({
toString : function() { console.log("hello : ", this); },
constructor : function Human (name) {
console.log("human constructor");
this.name = name
}
});
//Someone inherits of Human
var SomeOne = Human.extend({
constructor : function SomeOne (name){
//call parent constructor
SomeOne.__super__.constructor.call(this, name);
}
});
var Bob = new Human("Bob");
Bob.toString();
var Sam = new SomeOne("Sam");
Sam.toString();
//Static members
var Human = Kind.extend({
toString : function() { console.log("hello : ", this); },
initialize : function (name) {
console.log("human constructor");
this.name = name
}
},{ //Static
counter : 0,
getCounter : function() { return this.counter; }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment