我们什么时候可以忽略“窗口”。在全球市场上?

时间:2019-06-20 01:50:28

标签: globals window-object sharepoint-discussion-board

我想清除代码并在不需要的地方删除window.

要执行此操作的规则是什么?

我问全局调用是否必须具有window.-或全局 object -但我不询问用户定义< / em> this question中的变量没有我想要的答案...

我不想要有关如何组织变量和调用的建议(如已接受的答案)。我已经知道我的变量了-所以第二个答案都不适合。第三个答案可以转换为我要求的一些规则:

  • 如果if (window.myVar) {//do work }存在,示例myVar可以工作,但是如果缺少window.则错误!
  • 示例if (window.myVar) {//do work }可能比if (typeof myVar === 'array') {//do work }更精确,或者使用'string','function'...
  • 示例var myVar = 'test'window.myVar = 'test'大致相等...在这里user defined variable :(不用担心:)如果它有很大的价值,那就告诉它。尝试查找链接和参考,MDN,w3c,...

我们可以一起列出规则列表,询问是否可以安全从示例window.addEventlistener()中删除event.clientX

例如,我认为没有人写window.document.getElementById()。如果读者可能认为例如window.是用户定义的,那么有时最好明确提及history.back()

考虑以下全局变量:

for (var x in window) console.log(x)

以下是Chrome中控制台的输出:

blur focus close frames self window parent opener top length closed
location document origin name history locationbar menubar personalbar
scrollbars statusbar toolbar status frameElement navigator applicationCache
customElements external screen innerWidth innerHeight scrollX pageXOffset
scrollY pageYOffset screenX screenY outerWidth outerHeight devicePixelRatio
clientInformation screenLeft screenTop defaultStatus defaultstatus
styleMedia onanimationend onanimationiteration onanimationstart onsearch
ontransitionend onwebkitanimationend onwebkitanimationiteration
onwebkitanimationstart onwebkittransitionend isSecureContext onabort
onblur oncancel oncanplay oncanplaythrough onchange onclick onclose
oncontextmenu oncuechange ondblclick ondrag ondragend ondragenter
ondragleave ondragover ondragstart ondrop ondurationchange onemptied
onended onerror onfocus oninput oninvalid onkeydown onkeypress onkeyup
onload onloadeddata onloadedmetadata onloadstart onmousedown onmouseenter
onmouseleave onmousemove onmouseout onmouseover onmouseup onmousewheel
onpause onplay onplaying onprogress onratechange onreset onresize onscroll
onseeked onseeking onselect onstalled onsubmit onsuspend ontimeupdate
ontoggle onvolumechange onwaiting onwheel onauxclick ongotpointercapture
onlostpointercapture onpointerdown onpointermove onpointerup onpointercancel
onpointerover onpointerout onpointerenter onpointerleave onafterprint
onbeforeprint onbeforeunload onhashchange onlanguagechange onmessage
onmessageerror onoffline ononline onpagehide onpageshow onpopstate
onrejectionhandled onstorage onunhandledrejection onunload performance stop
open alert confirm prompt print requestAnimationFrame cancelAnimationFrame
requestIdleCallback cancelIdleCallback captureEvents releaseEvents
getComputedStyle matchMedia moveTo moveBy resizeTo resizeBy getSelection
find webkitRequestAnimationFrame webkitCancelAnimationFrame fetch btoa atob
setTimeout clearTimeout setInterval clearInterval createImageBitmap scroll
scrollTo scrollBy onappinstalled onbeforeinstallprompt crypto ondevicemotion
ondeviceorientation ondeviceorientationabsolute indexedDB webkitStorageInfo
sessionStorage localStorage visualViewport speechSynthesis
webkitRequestFileSystem webkitResolveLocalFileSystemURL openDatabase chrome
caches tilesAreLoaded numDdllogResponsesReceived lastDdllogResponse
onDdllogResponse LocalNTP $ getChromeUILanguage configData x TEMPORARY
PERSISTENT addEventListener removeEventListener dispatchEvent

我不要求列出所有带有使用不使用的单词。并非所有情况都能知道,window.是否可以删除,只是在某些情况下是很好。这不仅对我的工作感兴趣,而且与他人分享也应引起兴趣。

我不擅长从w3c读取它,但是认为知道编译器如何解决丢失的window.的人还有很多话要说。对我们来说,那真的很不错!

0 个答案:

没有答案