MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/btxz72/what_are_some_javascript_things_beginners_dont/ep60nw9?context=9999
r/javascript • u/[deleted] • May 28 '19
383 comments sorted by
View all comments
61
[removed] — view removed comment
28 u/[deleted] May 28 '19 more importantly, understanding the different contexts of this:this in the global space => windowthis in a function => function contextthis in a method of an object => the objectthis with call/apply/bind => whatever you want it to beedit for ES6: this is not bound in arrow functions, so the value bound outside the arrow function will be found and used instead. 0 u/[deleted] May 28 '19 [deleted] 1 u/[deleted] May 28 '19 can you give me an example of how runninglet o = { f: function() { console.log(this); } };o.f();prints out anything except the Object o?Also, to your first point, yes you can change the context at the call point with call/apply/bind, however, am I wrong to say that this applies to the closure created by the function in non call/apply/bind cases? → More replies (2)
28
more importantly, understanding the different contexts of this:
this in the global space => window
this in a function => function context
this in a method of an object => the object
this with call/apply/bind => whatever you want it to be
edit for ES6: this is not bound in arrow functions, so the value bound outside the arrow function will be found and used instead.
0 u/[deleted] May 28 '19 [deleted] 1 u/[deleted] May 28 '19 can you give me an example of how runninglet o = { f: function() { console.log(this); } };o.f();prints out anything except the Object o?Also, to your first point, yes you can change the context at the call point with call/apply/bind, however, am I wrong to say that this applies to the closure created by the function in non call/apply/bind cases? → More replies (2)
0
[deleted]
1 u/[deleted] May 28 '19 can you give me an example of how runninglet o = { f: function() { console.log(this); } };o.f();prints out anything except the Object o?Also, to your first point, yes you can change the context at the call point with call/apply/bind, however, am I wrong to say that this applies to the closure created by the function in non call/apply/bind cases? → More replies (2)
1
can you give me an example of how running
let o = { f: function() { console.log(this); } };
o.f();
prints out anything except the Object o?
Also, to your first point, yes you can change the context at the call point with call/apply/bind, however, am I wrong to say that this applies to the closure created by the function in non call/apply/bind cases?
→ More replies (2)
61
u/[deleted] May 28 '19
[removed] — view removed comment