【发布时间】:2016-01-16 09:27:33
【问题描述】:
我正在尝试废除 jQuery,因为我只需要它来做很少的事情,而是使用纯 JavaScript
我有这个原始代码:
this.bar = el.find('.bar');
this.options = $.extend({
delay: $.toInt(el.data('delay')) || 2000
}, options);
我试着用这个来转换它:
function foo(el, options) {
..................
this.bar = el.querySelectorAll(".bar");
this.options = extend({
delay: parseInt(el.data('delay')) || 2000 < -- - problem
}, options);
}
function extend(first, second) {
for (var secondProp in second) {
var secondVal = second[secondProp];
if (secondVal && Object.prototype.toString.call(secondVal) === "[object Object]") {
first[secondProp] = first[secondProp] || {};
extend(first[secondProp], secondVal);
} else {
first[secondProp] = secondVal;
}
}
return first;
};
但我收到此错误:
“未捕获的类型错误:el.data 不是函数”
有人对如何修复有任何想法吗?
【问题讨论】:
标签: javascript jquery ecmascript-6 ecmascript-5