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

2016-08-06 12:04 GMT+10:00 Xidorn Quan <quanxunzhen@gmail.com>:

>
> 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))
>

这里说错了一点点,body是一个很特殊的Element,它和Window有共有一些Event
Handler(定义在WindowEventHandler的部分)。把命令改成
Object.keys(window).filter(n => n.match(/^on/) && !(n in
document.createElement('div')))
剩下的是
[ "ondevicemotion", "ondeviceorientation", "onabsolutedeviceorientation",
"ondeviceproximity", "onuserproximity", "ondevicelight", "onafterprint",
"onbeforeprint", "onbeforeunload", "onhashchange",  "onlanguagechange",
"onmessage", "onoffline", "ononline", "onpagehide", "onpageshow",
"onpopstate", "onstorage", "onunload" ]
(Chrome增加那些animation和transition的)

实际上也还是很有限,大部分是Window所固有的,还有一些老的标准,或者是本来也没几个事件不值得添加新接口的标准。

- Xidorn

Received on Saturday, 6 August 2016 02:18:48 UTC