Skip to content

Instantly share code, notes, and snippets.

@medikoo
Created October 17, 2011 13:25
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 medikoo/1292600 to your computer and use it in GitHub Desktop.
Save medikoo/1292600 to your computer and use it in GitHub Desktop.
OOP in JS
// 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