Comments (12)
其实在无论是在 Event 上扩展 还是 navigator 上扩展,都是一个全局的查询能力,只是一个能力归属放在哪个 global 对象下更合适的问题。而对于某些 element 的特定事件,上述 @wssgcg1213 比如 的 InputEvent 能力,属于某个 element 的特定能力,所以如果提供 element 级别的查询,使开发者可以感知某个具体的 element 支持哪些事件。
from chinese-ig.
isEventSupports()
会更好一点吧
from chinese-ig.
赞
- 确实有必要,日常开发中经常会遇到这种探测判断的场景,比如屏幕横竖屏切换事件,如果有相关的检测方法的话,会更方便以及代码的可读性更高。
- 可能在 Event 静态方法上扩展会跟合适一些,毕竟 Event 对象基本在所有的环境中都存在。
- 上述的 API 方式都不错,我这里也提供一种供参考的方式
const isSupports = Event. supports('dbclick');
。
from chinese-ig.
- 这个问题确实是存在的,对于事件的特征判断目前缺乏有效路径,尽管有一些事件有 InputEvent 这类 Constructor, 但是像
load
这样的simple event
是没有构造器的 - 3 个方案我倾向于 1, 事件支持是由 UserAgent(浏览器) 的实现来决定的, 所以这类判断放在 navigator 下会符合逻辑吧~ 其次 Event 也是不错的, 至于是否要区分 UI Event 和其它 Event 可以再讨论看看
from chinese-ig.
看起来挺有用的,在标准层面感觉和HTML/DOM关系比较大,可以考虑在这个issue里先讨论一下这个提案的使用场景和建议语法,初步成型后提到DOM标准?
这是一个DOM的新特性提案的例子,可供参考(不过这个提案比我们讨论的这个要复杂得多):https://github.com/mfreed7/declarative-shadow-dom/blob/master/README.md
from chinese-ig.
考虑到特定元素的一些特有事件,以及 window 上的 onload 事件等,更倾向放在 EventTarget 上提供一个基础能力。继承 EventTarget 的 class 如果有自己的特有事件,可以覆盖该方法提供特有的一些事件判断。
from chinese-ig.
@xfq 已补充相关提案文档 https://github.com/answershuto/isEventSupports
from chinese-ig.
谢谢 @answershuto 。简单看了一下你的提案,有两点建议:
- 我觉得需要写一下为什么不能使用
if (window.MouseEvent)
或者if ("onxxxxx" in window)
这样的用法,因为这可能是常见问题 - 例子里写的
isEventSupports(Event event);
和下面的.isEventSupports('click');
不匹配,可能需要改为isEventSupports(DOMString eventType);
from chinese-ig.
感谢 @xfq 的宝贵建议,相关内容我已经修改以及增加在文档中了。
https://github.com/answershuto/isEventSupports#other-considerations
from chinese-ig.
感谢 @answershuto
如果其他同学没有新的comment,我觉得可以在DOM提一个issue了:https://github.com/whatwg/dom/issues
Issue里可以简单介绍一下这个提案,再加一个到 https://github.com/answershuto/isEventSupports 的链接。
from chinese-ig.
另外,提案有一个小typo:最后的input will return ture应该是input will return true
from chinese-ig.
感谢 @xfq ,相关内容已修改。
DOM issue 见 whatwg/dom#968
from chinese-ig.
Related Issues (10)
- committing Chinese Web IG f2f meeting English page HOT 1
- 小程序和快应用的英文名 HOT 16
- Chinese Web IG TPAC F2F agenda (Fukuoka, Sep 20 2019) HOT 1
- Exploring cultural expectations re: privacy and security
- CSS Display Sliver 提案的讨论 HOT 7
- 关于实现常用手势事件提案的讨论 HOT 4
- Is w3.org blocked in China? HOT 2
- bk HOT 1
- 【Task Force】召集小程序标准化的讨论 HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chinese-ig.