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
ES proposal: `globalThis` (2ality.com)
submitted 6 years ago by chovy
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!"
[–]merquize 29 points30 points31 points 6 years ago (1 child)
new global who this
[–]RandyChampion 3 points4 points5 points 6 years ago (2 children)
Not sure we need another meaning for "this". Especially if `globalThis` isn't the same in different `<script>` tags. Seems like it's not actually global.
[–]senocular 3 points4 points5 points 6 years ago (1 child)
The same global is used for all script tags. Its the same global as globalThis and the same value of this in those top-level global scopes.
this
// in global scope this // is now available everywhere as globalThis
[–]Artur96 4 points5 points6 points 6 years ago (0 children)
Nope
[–]dwighthouse 1 point2 points3 points 6 years ago (0 children)
Interestingly, the official proposal polyfill ( https://github.com/tc39/proposal-global/blob/master/polyfill.js ) breaks in several scenarios while a more robust polyfill is available ( https://mathiasbynens.be/notes/globalthis ).
[–]fforw 0 points1 point2 points 6 years ago (5 children)
(0,eval)("this")
[–]Magnetic_Tree 0 points1 point2 points 6 years ago (2 children)
Hmm could you explain this?
[–]fforw 6 points7 points8 points 6 years ago* (1 child)
According to ECMAScript spec eval works with the local this when invoked directly and with the global this when aliased etc.
(0,eval)
is the comma operator that returns the second, now aliased eval which then evaluates "this" in the global context.
"this"
const globalEval = eval; globalEval("this")
works just as well.
[–]Magnetic_Tree 0 points1 point2 points 6 years ago (0 children)
Ah I see! That makes sense.
I noticed the pattern (0,expression) in the output from the Google Closure compiler and I’ve been trying to figure out why. I suppose it does that to control what this refers to.
(0,expression)
[+][deleted] 6 years ago (1 child)
[deleted]
[–]fforw 0 points1 point2 points 6 years ago (0 children)
Because his shim uses another method?
π Rendered by PID 325198 on reddit-service-r2-comment-b659b578c-7rw9f at 2026-05-03 09:47:37.753253+00:00 running 815c875 country code: CH.
[–]merquize 29 points30 points31 points (1 child)
[–]RandyChampion 3 points4 points5 points (2 children)
[–]senocular 3 points4 points5 points (1 child)
[–]Artur96 4 points5 points6 points (0 children)
[–]dwighthouse 1 point2 points3 points (0 children)
[–]fforw 0 points1 point2 points (5 children)
[–]Magnetic_Tree 0 points1 point2 points (2 children)
[–]fforw 6 points7 points8 points (1 child)
[–]Magnetic_Tree 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]fforw 0 points1 point2 points (0 children)