[英]TypeError: x.y is not a function, when apparently it is
I'm experiencing a strange behavior off of javascript yet again. 我再次遇到javascript的奇怪行为。 I find this to be extremely illogical and confusing.
我发现这是非常不合逻辑和令人困惑的。
I probably did kind of a mess drawing over the picture but briefly, you see that $$('h2')
is clearly an object which has a method on
, or in javascript language a property on
which turns out to be a function, however when I try to access that function I get a TypeError? 我可能没有那种乱七八糟画过一张,但简单地说,你看,
$$('h2')
显然是其中有一个方法的对象on
,或者在财产JavaScript语言on
证明这是一个函数,但是当我尝试访问该函数时,我得到一个TypeError?
MY QUESTION IS: Why am I getting this error when obviously the object does have a property called on
which is a function? 我的问题是:当显然对象确实有一个叫做
on
的属性时,为什么我会收到这个错误?
EDIT: Here's the on
function 编辑:这是
on
函数
on: function(event, func) {
this.node.addEventListener(event, func, false);
}
You've missed the leading [
in your console output. 您错过了
[
在您的控制台输出中的前导[
。 The object you're printing is an array whose first element has an on
property. 您要打印的对象是一个数组,其第一个元素具有
on
属性。
You likely want $$('h2')[0].on(...)
instead. 你可能想要
$$('h2')[0].on(...)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.