I have a js object like this:
let service = function () {
this.a = 100;
}
service.prototype.func = function() {
console.log(this.a)
}
service.prototype.func2 = function () {
console.log('func2')
this.func();
}
service.prototype.obj = {
m: {
n: {
o: function() {
this.func2();
},
p: service.prototype.func2.bind(service.prototype)
}
}
}
I want to access the 'a' from o or p, here's the code:
let s = new service();
console.log(s.a)
s.func()
s.func2()
s.obj.m.n.p()
s.obj.m.n.o()
and the output is
100
100
func2
100
func2
undefined
test.js:20
this.func2();
^
TypeError: this.func2 is not a function
Any idea that how I can write o/p properly to perform like func2?