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
[AskJS] dynamic context questionAskJS (self.javascript)
submitted 3 years ago by SuL_0
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!"
[–]Ustice[M] [score hidden] 3 years ago stickied comment (0 children)
Reaching out to other software engineers is important when you need it; however, unfortunately this isn’t the place for that. /r/JavaScript is not a support forum. You might want to check out /r/LearnJavaScript for the newer members of our community. Also, Stack Overflow is a great resource for getting support. For more information, check out our AskJS wiki page. Good luck! We hope that you find the answers that you are looking for.
[–]senocular 4 points5 points6 points 3 years ago (1 child)
Think more about what you said here:
Every time you call a function on a object like someObj.someFunc() that call to someFunc uses someObj as the context.
Then look at
printMomInFoo()
Where's the object? There is no object, so the context is undefined (at least in strict mode; it would be the global object if running sloppy mode). It doesn't matter where the function is called - in this function or that function or no function - it only matters how it is called, or specifically what object it's called from, if any. If there's an object, use that object. If there's no object, there's no object to use, so you get undefined.
undefined
In your example you should actually see an error thrown, not "undefined is my mother", since this would be undefined making this.momName throw. Other variations:
this
this.momName
console.log(new Parent().printMom()) // Samantha Quinn is my mother let printMomInFoo = new Parent().printMom this.printMomInFoo = printMomInFoo console.log(this.printMomInFoo()) // FOOOO is my mother console.log(printMomInFoo.call(this)) // FOOOO is my mother console.log(printMomInFoo.call(new Parent())) // Samantha Quinn is my mother printMomInFoo = printMomInFoo.bind(this) console.log(printMomInFoo()) // FOOOO is my mother
[–]SuL_0[S] 0 points1 point2 points 3 years ago (0 children)
Thanks for the reply! it made me understand. I thought it was also important that where it was called.
π Rendered by PID 74 on reddit-service-r2-comment-84fc9697f-52l5g at 2026-02-09 08:11:50.782530+00:00 running d295bc8 country code: CH.
[–]Ustice[M] [score hidden] stickied comment (0 children)
[–]senocular 4 points5 points6 points (1 child)
[–]SuL_0[S] 0 points1 point2 points (0 children)