-
-
Save pragmaticlogic/5462824 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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