Last active
December 12, 2015 10:49
-
-
Save skeep/4762019 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 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