0
How can I access parent function scope at this example?
6 Respuestas
+ 3
function Slider(elementClass)
{
this.element = elementClass;
this.printClass = function () {
console.log(this.element);
}
}
let slider = new Slider(".slider-elem");
slider.printClass();
0
visph thanks it works but why this keyword don't return child function scope?
0
because this refer to the object on wich you apply the method (function) called...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
0
you mean if this used inside object it will refer that object?
if that this means if i make a nested object this will refer to it?
0
read the page(s) from the link I gave to you: it will explain how 'this' works, in different context...
what are you calling "a nested object"? A function constructor defined into another one? An instance initialized inside the outer constructor and of that "nested" constructor? or rather an instance initialized inside the outer constructor of another constructor outside? or...
maybe provide a code to clarify your question ^^
0
ok thank you too much