프로토 타입되지 않았거나 underscore.js/backbone.js의 dom 객체가 아닌 객체에서 사용자 정의 이벤트를 수신하는 방법을 알아 내려고합니다.언더 코어/백본의 동적 객체에 이벤트 바인딩
예를 들어:
//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'
이 더 바인딩 프로그래머없는 의미가 있습니다 개체에 있지만이 누구를위한 좋은 해결책을 가지고있다?
정말 감사합니다