Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created October 29, 2011 20:41
Show Gist options
  • Save Raynos/1325067 to your computer and use it in GitHub Desktop.
Save Raynos/1325067 to your computer and use it in GitHub Desktop.
var Proto = function (thing) {
this.thing = thing;
};
Proto.prototype.method = function () {
return this.thing;
};
Proto.prototype.prop = 42;
var p = new Proto("someThing");
p.method(); // "someThing"
var Proto = {
prop: 42,
method: function () {
return this.thing;
},
constructor: function (thing) {
this.thing = thing;
}
};
// instantiate
var p = Object.create(Proto);
// initialize
p.constructor("someThing");
// call method
p.method(); // "someThing"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment