I am calling function which return result to callback(this is old library) by using prototype apply
. But after this I'am losing my this
scope in the callback.
export default {
CONSTANCT: 123,
x () {
var arr = [1, 2, this.yCallback]
this.y.apply(this, arr) //trying give null instead this, but now works too
},
y (a, b, callback) {
var c = a + b
callback(c)
},
yCallback (result) {
console.log(result)
console.log(this.CONSTANCT)
}
}
in yCallback
function this
- undefined
Changing string callback(c)
to callback.apply(this, [c])
resolve the problem. But i really want to avoid library fixes