我是 JS 新手并试图覆盖 Craftyjs 中的一个函数,这是我的代码:
Crafty.c('TestA', {
init: function() {
Crafty.addEvent(this, Crafty.stage.elem, "mousedown", this._e_clickListener);
},
_e_clickListener: function(e){
this.foo();
},
foo: function() {
console.log('call A foo');
}
});
Crafty.c('TestB', {
init: function() {
this.requires('TestA');
},
foo: function(){
console.log('call B foo');
}
});
Crafty.e('TestB');
当我点击画布时的结果是:
call A foo
有没有办法把它变成'call B foo'呢?谢谢。