Skip to content

Instantly share code, notes, and snippets.

@skeep
Created February 12, 2013 10:34
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 skeep/4761463 to your computer and use it in GitHub Desktop.
Save skeep/4761463 to your computer and use it in GitHub Desktop.
var cardJSON = {
text:'this is text',
color:'red'
};
var Card = function(obj){
var that = this;
var props = Object.getOwnPropertyNames(obj);
props.forEach(function(prop){
var propDescriptor = Object.getOwnPropertyDescriptor(obj, prop);
that[prop] = propDescriptor.value
});
function setColor(color){
that.color = color;
}
return {
props : that,
setColor : setColor
};
};
var card1 = new Card(cardJSON);
console.log(card1.props.color);
card1.setColor('blue');
console.log(card1.props.color);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment