Wrapping imported construtor in a promise

2019-09-11 02:28发布

问题:

I have the same problem as Promisify imported class (constructor) with bluebird in ES6 + babel. The accepted answer seems to have a bug but I couldnt comment on that thread (not enough reputation points), so am creating a new question. The bug seems to be in:

var o = new lib.C(); // get object
o.then(function(data){
    // access data
});

I get a run-time error:

~/node_modules/bluebird/js/main/promise.js:114
    return this._then(didFulfill, didReject, didProgress,
                ^ TypeError: undefined is not a function
    at C.Promise.then (~/node_modules/bluebird/js/main/promise.js:114:17)
    at Object.<anonymous> (~/temp/jsex.js:367:3)
    at Module._compile (module.js:460:26)

Can somebody post a working sample? Or point out if I'm missing something?