2013-04-30 89 views

回答

7

这是因为你绑定回调的方式。更改

service.$on('hello', service.method); 

service.$on('hello', function() { 
    service.method(); 
}); 

当你说spyOn(service, 'method'),你说“更换在service.method有间谍参考的价值。”但是,您的原始service.$on代码不会在触发事件时查找service.method 上的值 - 只需在服务初始化时查看。因此,更改service.method指向后面的引用不起作用。