[英]Undefined even with null check
listener 返回 undefined,我相信 start 属性。 这是一个观察者对象。
var updateP = {
cb: function (event, properties) {
"listener" in window? listener.next(properties):null
},
start: function (listener) {
dataset.on("update", this.cb)
},
stop: function () {
dataset.off("update", this.cb)
},
}
listener
变量是start
函数的本地变量,因此您无法将其作为全局变量访问。
将this.cb
的定义移动到updateP.start
,然后它就可以访问词法变量了。
var updateP = { start: function(listener) { function asdf(ab) { console.log(ab) } this.cb = function(event, properties) { listener.next(properties) }; dataset.on("update", this.cb) }, stop: function() { if (this.cb) { dataset.off("update", this.cb); } }, }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.