Created
February 12, 2013 10:34
-
-
Save skeep/4761463 to your computer and use it in GitHub Desktop.
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 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