171
rated 0 times
[
178]
[
7]
/ answers: 1 / hits: 38791
/ 8 Years ago, tue, april 19, 2016, 12:00:00
Is there any way that would allow me to call a class as a function. I'm looking to have the functionality below, where there's a main
method within the class and that's the one I want to have the method execute.
class test {
constructor () {
return this.main
}
main () {
return Promise.resolve('thomas')
}
}
test().then(name => {
console.log(name)
})
It seems my only other option would be to have a wrapper function like this.
class Test {
constructor (name) {
this.name = name
}
main () {
return Promise.resolve(this.name)
}
}
let test = (name) => {
return new Test(name).main()
}
test('thomas').then(name => {
console.log(name)
})
More From » class