Учитывая следующий код JS, при вызове bar.fun
через bar.fun.call(b, 'hi');
как я могу сказать компилятору, что я хочу, чтобы this
был экземпляром Banana
?
/**
* @typedef {Object} Bar
* @property {function(this:Foo, string):number} fun
*/
class Foo {
constructor(){
this.n = 1;
};
}
class Banana extends Foo {
constructor() {
super();
this.b = 2;
};
}
const b = new Banana();
/** @type {Bar} */
const bar = {
/**
* @this {Banana}
* @param {string} s
* @return {number}
*/
fun(s) {
return this.n + this.b + s.length; //Property 'b' does not exist on type 'Foo'
}
};
bar.fun.call(b,'hi');