Re: 提议讨论:将绑定在 window 上的事件模块化拆分

2016-08-06 2:35 GMT+10:00 锦江 赵 <zhaojinjiang@me.com>:
>
> 我刚才在本地 Chrome 空白页里搜索了一下所有支持的事件:
>
> Object.keys(window).filter(n => n.match(/^on/))
> ["ondeviceorientationabsolute", "ondeviceorientation", "ondevicemotion",
> "onunhandledrejection", "onrejectionhandled", "onunload", "onstorage",
> "onpopstate", "onpageshow", "onpagehide", "ononline", "onoffline",
> "onmessage", "onlanguagechange", "onhashchange", "onbeforeunload",
> "onwaiting", "onvolumechange", "ontoggle", "ontimeupdate", "onsuspend",
> "onsubmit", "onstalled", "onshow", "onselect", "onseeking", "onseeked",
> "onscroll", "onresize", "onreset", "onratechange", "onprogress",
> "onplaying", "onplay", "onpause", "onmousewheel", "onmouseup",
> "onmouseover", "onmouseout", "onmousemove", "onmouseleave", "onmouseenter",
> "onmousedown", "onloadstart", "onloadedmetadata", "onloadeddata", "onload",
> "onkeyup", "onkeypress", "onkeydown", "oninvalid", "oninput", "onfocus",
> "onerror", "onended", "onemptied", "ondurationchange", "ondrop",
> "ondragstart", "ondragover", "ondragleave", "ondragenter", "ondragend",
> "ondrag", "ondblclick", "oncuechange", "oncontextmenu", "onclose",
> "onclick", "onchange", "oncanplaythrough", "oncanplay", "oncancel",
> "onblur", "onabort", "onwheel", "onwebkittransitionend",
> "onwebkitanimationstart", "onwebkitanimationiteration",
> "onwebkitanimationend", "ontransitionend", "onsearch", "onanimationstart",
> "onanimationiteration", "onanimationend"]
>
> 发现里面的事件非常多,里面有相当一部分是和某些独立的 W3C JavaScript APIs Spec 强关联的,比如 onstorage 和
> web storage API 规范相关联,ondevicemotion 和 device orientation event
> 规范相关联,onpopstate 和 History API 规范相关联。
>

你这里列的大多数事件都不是Window对象特有的,而是Window对象和Element对象共有的。如果你把你的命令改成
Object.keys(window).filter(n => n.match(/^on/) && !(n in document.body))

你就会发现剩下的没几个了。在Firefox里,剩下的只有
[ "ondevicemotion", "ondeviceorientation", "onabsolutedeviceorientation",
"ondeviceproximity", "onuserproximity", "ondevicelight" ]
而在Chrome里稍微多一些,为
["ondeviceorientationabsolute", "ondevicelight", "ondeviceorientation",
"ondevicemotion", "onwebkittransitionend", "onwebkitanimationstart",
"onwebkitanimationiteration", "onwebkitanimationend", "ontransitionend",
"onanimationstart", "onanimationiteration", "onanimationend"]

而多的只是
on{webkit,}{transition,animation}*。实际上这几个事件实际上也是Element上的,但标准里面没有任何地方有这几个attribute,会有这些纯粹只是WebKit系的历史问题。

所以实际上一点也不多,已经存在的很可能也只是历史问题,新的API自然会进到新的对象里去。

- Xidorn

Received on Saturday, 6 August 2016 02:05:43 UTC