Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created July 1, 2011 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gozala/1058534 to your computer and use it in GitHub Desktop.
Save Gozala/1058534 to your computer and use it in GitHub Desktop.
ES discussion on prototype focused classes.
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() { .... };
// Would be better if it was just Object
var Foo = Object.prototype <| {
initialize (options) { ... },
do_foo_job() { ... }
}
var Bar = Foo <| {
do_bar_job() { ... }
}
// 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