var page={
init:function(){
this.initEvents()
},
bindEvent: function (target, type, name) {
$(target).bind(type, function (e) {
e.preventDefault();
name(e)
})
},
initEvents: function () {
this.bindEvent('.pic-egg1', 'click', this.showDiag)
this.bindEvent('.pic-egg2', 'click', this.showDiag)
},
showDiag: function () {
this.hideDiag()
},
hideDiag:function(){
console.log('出不来')
}
}
控制器报这个错误
hideDiag is not a function
$('#foo').bind(event, eventHandler)
中的eventHandler
指向#foo
选择器代表的 dom 元素本身,所以就会出现xx is not function
的错误了。要解决的话,很简单啊,使用
bind
、apply
或者call
绑定方法至page
对象即可。