Created
December 11, 2012 18:35
-
-
Save AdamBrodzinski/4260906 to your computer and use it in GitHub Desktop.
Backbone like getter and setter methods
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
var Car = function () { | |
this.attributes = { | |
color: null, | |
wheels: 4, | |
speed: null | |
}; | |
}; | |
Car.prototype.set = function (key, value) { | |
this.attributes[key] = value; | |
return this; | |
}; | |
Car.prototype.get = function (propKey) { | |
return this.attributes[propKey]; | |
}; | |
myCar = new Car(); | |
myCar.set('color', 'red') | |
.set('wheels', 3) | |
.set('speed', 'fast'); | |
console.log( myCar.get('color') ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment