Skip to content

Instantly share code, notes, and snippets.

@Zabanaa
Created June 25, 2016 18:22
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 Zabanaa/96d2633552a4823cafaa22362b286b6c to your computer and use it in GitHub Desktop.
Save Zabanaa/96d2633552a4823cafaa22362b286b6c to your computer and use it in GitHub Desktop.
Just playing around with object.assign
(function(){
window.Player = function(config = {}){
this.defaults = {
name: "Karim Benzema",
age: 29,
position: "CF",
club: "Real Madrid CF"
}
this.options = Object.assign({}, this.defaults, config)
}
Player.prototype.introduce = function(){
console.log(`Hey my name is ${this.options.name}, I'm ${this.options.age} years old, I play as a ${this.options.position} for ${this.options.club}`)
}
})()
const Nasri = new Player({
name: "Samir Nasri",
age: 28
})
const BenArfa = new Player({
name: "Hatem Ben Arfa",
age: 27,
club: "Sevilla CF"
})
const Benz = new Player()
Nasri.introduce()
console.log("=========")
BenArfa.introduce()
console.log("=========")
Benz.introduce()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment