Created
June 25, 2016 18:22
-
-
Save Zabanaa/96d2633552a4823cafaa22362b286b6c to your computer and use it in GitHub Desktop.
Just playing around with object.assign
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
(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