Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
请在此处查看演示:http: //jsfiddle.net/mA6qm/1/(扩展控制台)
为什么两个对象之间没有发送或接收事件,但将相同的代码放在全局范围内时可以正常工作?
问题是您将事件绑定到的对象与您触发它的对象不同。在setTimeout回调中,即使您定义为该对象上的方法,this也不会引用。相反,它将引用窗口。同样,当您绑定事件时,该事件被绑定在. 您需要确保两者都使用相同的对象。calling_objectfinishedlistening_object
setTimeout
this
calling_object
finished
listening_object