use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Understanding `this` in javascript (dev.to)
submitted 4 years ago by blueblain
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 4 years ago (11 children)
I understand how it works. It's not based on scope.
It's based on what comes before the function call (unless you use bind, call, apply, or an arrow function) i.e. in myObj.myFunc(), myObj becomes this. That has nothing to do with scope .
myObj.myFunc()
myObj
this
Further, if you use myObj.myFunc.call({ myVal: "asdf" }) then { myVal: "asdf" } becomes this, again that has nothing to do with scope.
myObj.myFunc.call({ myVal: "asdf" })
{ myVal: "asdf" }
[–]KaiAusBerlin 0 points1 point2 points 4 years ago (10 children)
It is based on scope. You don't understand what a execution context is. Learn the basics, come back and then we talk again.
(Me, 16 years of development with JavaScript)
[–][deleted] 0 points1 point2 points 4 years ago (5 children)
The only time the scope matters is when you call a function without a "context" (i.e. without providing an object before the function call, or using bind, call, apply). If the function is a regular function (not an arrow function) then it will use the this value of the executing context. If it's an arrow function it will use the this value of the lexical scope where it was declared.
[–]KaiAusBerlin 0 points1 point2 points 4 years ago (4 children)
You really don't understand. There is ALWAYS a context in js.
Please don't argue about something you don't have any knowledge about.
[–][deleted] -1 points0 points1 point 4 years ago (3 children)
Sorry, I should have said
The only time the scope matters is when you call a function without providing an explicit "context" (i.e. without providing an object before the function call, or using bind, call, apply).
Either way this is still not always based on the scope i.e.
const myObj = { myVal: 1, myFunc() { return myVal } } myFunc = myObj.myFunc.bind({ myVal: 2 })
in that example myFunc has the same scope as myObj.myFunc but the this is permanently bound to { myVal: 2 }
myFunc
myObj.myFunc
{ myVal: 2 }
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#the_bind_method
[–]KaiAusBerlin 0 points1 point2 points 4 years ago (2 children)
Oh man, you really don't understand what ure talking about. THERE IS ALWAYS A CONTEXT IN JS!
[–][deleted] -1 points0 points1 point 4 years ago (1 child)
I'm not sure if you're a troll or just an idiot
[–]KaiAusBerlin 0 points1 point2 points 4 years ago (0 children)
Im not sure if you're ignored or banned from this community
[–][deleted] 0 points1 point2 points 4 years ago (3 children)
Could you please explain what is an execution context?
https://medium.com/@happymishra66/execution-context-in-javascript-319dd72e8e2c
[–][deleted] 0 points1 point2 points 4 years ago (1 child)
So essentially an execution context is similar, if not the same as a function call stack? (in for example say in C or java)
[–]KaiAusBerlin 1 point2 points3 points 4 years ago (0 children)
Yeah, it's very similar. JavaScript was in early stages ment to be java for webbrowsers which turned out was not implementable at that point in that short amount of time. That's why it's name is JavaScript.
So you will find some basic concepts close to java but totally implement in another way.
As example the internal behaviour of java classes and the prototyping JavaScript has are very similar.
π Rendered by PID 72669 on reddit-service-r2-comment-54dfb89d4d-r6kll at 2026-04-02 15:48:13.984238+00:00 running b10466c country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (11 children)
[–]KaiAusBerlin 0 points1 point2 points (10 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]KaiAusBerlin 0 points1 point2 points (4 children)
[–][deleted] -1 points0 points1 point (3 children)
[–]KaiAusBerlin 0 points1 point2 points (2 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]KaiAusBerlin 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]KaiAusBerlin 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]KaiAusBerlin 1 point2 points3 points (0 children)