Last active
August 29, 2015 14:10
-
-
Save stowball/a47df61e5b6a6f15ee92 to your computer and use it in GitHub Desktop.
Object create JavaScript pattern
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 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; | |
| } | |
| }; |
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
| 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