1
我想弄清楚如何偵聽自定義事件的對象尚未原型或不是dom對象在underscore.js/backbone.js。綁定事件動態對象在下劃線/主幹
例如:
//this is inside a view object
play: function(arg)
{
this.a = this.image(this.model.a);
this.a.bind("ready",start,this);//<--- causes error
this.b = this.image(this.model.b);
this.b.bind("ready",start,this);//<--- causes error
function start()
{
// do some stuff in here
}
//some more stuff
},
image: function(args)
{
// load the image, get its data, attach to original model then return it.
var args = args;
var img = $("<img/>");
var t = this;
img.load(function(){
t.pasteboard.drawImage(this,0,0);
args.imageData = t.pasteboard.getImageData(0,0,args.width,args.height);
args.ready = true;
args.trigger("ready",args);
}).attr("src",args.src).hide();
return args;
},
和模型看起來大致是這樣的:
a:{
src:"/img/a.jpg",
width:1320,
height:639,
x:0,
y:0,
opactiy:0,
scale:[1,1]
},
b:{
src:"/img/b.jpg",
width:1320,
height:639,
x:0,
y:0,
opactiy:0,
scale:[1,1]
},
和錯誤是:
Uncaught TypeError: Object #<Object> has no method 'bind'
當然這是有道理的,世界上沒有綁定在對象上,但任何人都得到了一個很好的解決方案呢?
非常感謝 一個