
[英]Are there any drawbacks to mixing arrow functions in javascript classes?
[英]Any drawbacks to using functions instead of classes for plain JavaScript components?
使用函数而不是类来构建普通的 JavaScript 组件是否会对性能产生重大影响或任何其他负面后果? 我更喜欢函数,因为我不必跟踪this
并且发现代码更易于阅读。 使用函数构建的一个示例组件如下:
function Dialog(dialog) {
const dialogId = dialog.id;
const trigger = document.querySelector(`[${DATA_TARGET}="${dialogId}"]`);
const backdrop = dialog.closest(SELECTOR_BACKDROP);
function show() {
...
}
function hide() {
...
}
trigger.addEventListener("click", show);
}
const dialogs = Array.from(document.querySelectorAll(SELECTOR_DIALOG));
dialogs.forEach((dialog) => Dialog(dialog));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.