Is it possible to manually define additional methods for an existing class?
My specific usecase is bluebird promisifyAll() , which:
Promotes the entire object by looking at the properties of the object and creating the asynchronous equivalent of each function of the object and its prototype chain ... http://bluebirdjs.com/docs/api/promise.promisifyall.html
Obviously, the thread will not be able to figure this out automatically. Therefore, I am ready to help. Question: HOW?
Consider the following code
import http from 'http' import { promisifyAll } from 'bluebird' promisifyAll(http) const server = http.createServer(() => { console.log('request is in'); }) server.listenAsync(8080).then(() => { console.log('Server is ready to handle connections') })
The stream here contains the following error:
property `listenAsync`. Property not found in Server
There would be no error if I used listen . smart enough to see that this is the real method defined in the module. But listenAsync is a dynamic addition of promisifyAll and invisible to the thread
source share