13th Jun 2021, 7:06 AM
Mustafa Emad
Mustafa Emad - avatar
6 Respostas
+ 3
function Slider(elementClass) { this.element = elementClass; this.printClass = function () { console.log(this.element); } } let slider = new Slider(".slider-elem"); slider.printClass();
13th Jun 2021, 7:07 AM
visph
visph - avatar
0
visph thanks it works but why this keyword don't return child function scope?
13th Jun 2021, 7:34 AM
Mustafa Emad
Mustafa Emad - avatar
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
13th Jun 2021, 7:37 AM
visph
visph - avatar
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?
13th Jun 2021, 7:40 AM
Mustafa Emad
Mustafa Emad - avatar
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 ^^
13th Jun 2021, 7:47 AM
visph
visph - avatar
0
ok thank you too much
13th Jun 2021, 7:50 AM
Mustafa Emad
Mustafa Emad - avatar