I am trying to use a method as a constructor inside another method. But when I do this I get the following TypeError:
TypeError: function is not a constructor (evaluating 'new self.f(1)')
and example code is:
class C{
constructor(v){
this.f(v);
this.g(v);
}
f(v){
this.v = v;
}
g(v){
var self = this;
function h(v){
this.v = v;
this.w = new self.f(1);
console.log(this.w);
}
new h(1)
}
}
var c = new C(1);
is there a reference error with self?
var x = new this.f(1);
just before thefunction h()
declaration you'll see that that doesn't work either. – Thomasinethomasonself
part wasn't the issue. Theclass
syntax is sugar, but (evidently) it's also a bit more complicated than that... – Thomasinethomasonthis.f.prototype
is alsoundefined
, so yea, it can't be used as a constructor. – GangC.f.prototype = {constructor: C.f}
it still doesn't let me use it as a constructor. There must be something more going on. – Epilepsy[[Construct]]
internal method. – Epilepsy