Skip to content

Instantly share code, notes, and snippets.

@AdamBrodzinski
Created December 11, 2012 18:35
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 AdamBrodzinski/4260906 to your computer and use it in GitHub Desktop.
Save AdamBrodzinski/4260906 to your computer and use it in GitHub Desktop.
Backbone like getter and setter methods
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