Last active
November 13, 2019 13:31
-
-
Save erdemuslu/8598317aecb8d496df49edd5f3b25080 to your computer and use it in GitHub Desktop.
This file contains 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
const createUser = (firstName, lastName) => { | |
const user = {}; | |
user.firstName = firstName; | |
user.lastName = lastName; | |
merge(user, methods); | |
return user; | |
} | |
const methods = { | |
sayHello: function() { | |
console.log(`Hello ${this.firstName} ${this.lastName}`); | |
} | |
} | |
const merge = function(obj, methods) { | |
for (const key in methods) { | |
obj[key] = methods[key]; | |
} | |
} | |
const user1 = createUser('Erdem', 'Uslu'); | |
const user2 = createUser('John', 'Smith'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment