Skip to content

Instantly share code, notes, and snippets.

@amorfati0310
Created October 23, 2019 13:41
Show Gist options
  • Save amorfati0310/ab5d1da6c6f17be7948d229de7009e08 to your computer and use it in GitHub Desktop.
Save amorfati0310/ab5d1da6c6f17be7948d229de7009e08 to your computer and use it in GitHub Desktop.
optionClass.js
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