Created
October 17, 2011 13:25
-
-
Save medikoo/1292600 to your computer and use it in GitHub Desktop.
OOP in JS
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
// Constructor way: | |
var Class = function (value) { | |
this.value = value; | |
}; | |
Class.prototype = { | |
property: 'value', | |
method: function () {} | |
}; | |
var obj = new Class(value); | |
// Object.create way: | |
var objproto = { | |
property: 'value', | |
method: function () {} | |
}; | |
var createObj = function (value) { | |
var obj = Object.create(objproto); | |
obj.value = value; | |
return obj; | |
}; | |
var obj = createObj(value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment