Created
October 23, 2019 13:41
-
-
Save amorfati0310/ab5d1da6c6f17be7948d229de7009e08 to your computer and use it in GitHub Desktop.
optionClass.js
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
var Person = class { | |
constructor(options) { | |
this.name = options.name; | |
[...Object.keys(options.methods)].forEach(key => { | |
this[key] = options.methods[key] | |
}) | |
} | |
} | |
const dali = new Person({ | |
name: 'dali', | |
methods: { | |
sayHello(){ | |
console.log(`hello I am ${this.name}`) | |
} | |
} | |
}) | |
dali.sayHello() | |
hello I am dali |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment