@jaffathecake Is there a reason code executed on the global scope is slower than the same code in a function called from the global scope. Same behaviour in other browsers bar Safari?
-
-
Replying to @jaffathecake @robmcm
It might also be an issue with the benchmark. How did you measure exactly? I don’t know why fn() would be slower, run-time wise, than (function() { fn() }()) — if anything I’d expect the opposite. +
@bmeurer2 replies 0 retweets 3 likes -
Well `var x` on global scope is a property of the global object whereas `var x` in a function is a stack local (or worst case context local). Accessing object properties is obviously slower than accessing stack slots.
1 reply 0 retweets 12 likes -
*goes and wraps entire codebase in IIFE*
3 replies 0 retweets 9 likes
Just use modules! Say no to the global scope :) (Or even just const/let.)
1 reply
1 retweet
7 likes
-
-
Heh, obviously. It’s more of an interesting question :)
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.