Created
July 1, 2011 13:22
-
-
Save Gozala/1058534 to your computer and use it in GitHub Desktop.
ES discussion on prototype focused classes.
This file contains 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
function Foo(options) { .... } | |
Foo.prototype.do_foo_job = function() { ... } | |
function Bar(options) { | |
if (!(this instanceof Bar)) | |
return this new Bar(options); | |
Foo.apply(this, arguments); | |
} | |
Bar.prototype = Object.create(Foo.prototype); | |
Bar.prototype.do_bar_job = function() { .... }; |
This file contains 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
// Would be better if it was just Object | |
var Foo = Object.prototype <| { | |
initialize (options) { ... }, | |
do_foo_job() { ... } | |
} | |
var Bar = Foo <| { | |
do_bar_job() { ... } | |
} |
This file contains 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
// Object.extend is just a proxy to Object.prototype.extend | |
var Foo = Object.extend({ | |
initialize: function(options) { ... }, | |
do_foo_job: function() { ... } | |
}) | |
var Bar = Foo.extend({ | |
do_bar_job: function() { ... } | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment