Skip to content

Instantly share code, notes, and snippets.

@skeep
Last active December 12, 2015 10:49
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/4762019 to your computer and use it in GitHub Desktop.
Save skeep/4762019 to your computer and use it in GitHub Desktop.
var cardJSON1 = {
text:'this is text',
color:'red',
position:{
x:200,
y:200
}
};
var cardJSON2 = {
text:'this is text',
color:'green',
position:{
x:200,
y:200
}
};
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
});
};
Card.prototype.setColor = function(color){
//console.log(this.color);
this.color = color;
};
Card.prototype.getColor = function(){
return this.color;
};
var card1 = new Card(cardJSON1);
console.log(card1);
//card1.setColor.apply(card1, ['blue']);
card1.color = 'blue';
console.log(card1.getColor());
//console.log(card1.getColor.apply(card1));
var card2 = new Card(cardJSON2);
console.log(card2);
card2.setColor('pink');
console.log(card2.getColor());
//console.log(card2.getColor.apply(card1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment