Created
October 29, 2011 20:41
-
-
Save Raynos/1325067 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
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" |
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
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