javascript - test表示什么?
本文介绍了javascript - test表示什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
在看https://zhuanlan.zhihu.com/p/...
里面一段代码
var supportsPassive = false;
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true;
}
});
window.addEventListener("test", null, opts);
} catch (e) {}
// Use our detect's results.
// passive applied if supported, capture will be false either way.
elem.addEventListener(
'touchstart',
fn,
supportsPassive ? { passive: true } : false
);
请问window.addEventListener("test", null, opts); 中test表示什么?
解决方案
啥也不是,你理解歪了,你可以把test定义成任意的合法字符串,这里写成test是要告诉你这是一个无意义的注册,永远不会被触发.
test不是核心点,核心是利用事件注册机制来执行 opts中的getter。
这篇关于javascript - test表示什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文