Replies: 1 comment
-
Not an easy question. I fit into the beginner category here - for example I find That's why I'd prefer Upshot, if we feel that we have to be consistent here (and I am not sure we do), then I think your proposal makes sense. @wbamberg Would be good to have your opinion on this. |
Beta Was this translation helpful? Give feedback.
-
This comes from mdn/content#27666. The question is: when referring to a global variable, do we prefix it with the global object?
My personal suggestion is we should avoid
window.
/self.
prefixes as much as possible, to ensure it can always be cross-platform.However, do we have different preferences for different properties?
window.AudioContext
).window.requestAnimationFrame()
) and is a big source of inconsistency.window.isSecureContext
,window.crypto
). For exmaple,window.localStorage
andwindow.console
are probably bizarre, but it’s more bizarre to know that we ALWAYS writewindow.crypto
andwindow.indexedDB
with the prefix, which I don't think is a good practice.Here is my proposed standard:
localStorage
,crypto
, includingconsole
)scrollTo()
,innerWidth
, … looks like it would also includealert()
/prompt()
?)If it helps, here's a list of
window.
prefixed globals throughout our code (some may be in macro calls, I just used a regex to match all content):Script to collect them:
Beta Was this translation helpful? Give feedback.
All reactions