Skip to content

Instantly share code, notes, and snippets.

@stowball
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save stowball/a47df61e5b6a6f15ee92 to your computer and use it in GitHub Desktop.

Select an option

Save stowball/a47df61e5b6a6f15ee92 to your computer and use it in GitHub Desktop.
Object create JavaScript pattern
var vector = {
_x: 1,
_y: 2,
create: function(x, y) {
var obj = Object.create(this);
obj.setX(x);
obj.setY(y);
return obj;
},
setX: function(value) {
this._x = value;
},
getX: function() {
return this._x;
},
setY: function(value) {
this._y = value;
},
getY: function() {
return this._y;
}
};
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
http://jaxenter.com/a-modern-approach-to-object-creation-in-javascript-107304.html
http://www.adobe.com/devnet/archive/html5/articles/javascript-object-creation.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment