在我的 jquery-plugin 中,完成动画后,我被称为“破坏”功能两次..有人纠正我的错误吗?
功能:
;(function ( $, window, document, undefined ) {
$.fn.BackendProcess = function(){
var that = this;
destroy = function(){
console.log(arguments.callee.caller.toString());//consoling 2 times
}
that.bind( "myEventStart", function( e ) {
$(this).css({width:"500"});
});
that.bind( "myEventEnd", function( e ) {
setTimeout(function(){
$(that).animate({width :"100"},{
easing: 'swing',
duration:2000
}).promise().done(function(){destroy()});
})
});
return{
start:function(){
that.trigger("myEventStart");
},
stop:function(){
that.trigger("myEventEnd");
},
destroy:function(){
console.log("distroy starts");
}
}
}
})( jQuery, window , document );
$(".myButton").BackendProcess().start();
$(".myButton").BackendProcess().stop();