Is it ok to bind jQuery events to plain, non-DOM Javascript objects:
var myobject = {};
$(myobject).bind(\"foobar\", function() { alert(\"daa\"); });
$(myobject
Seeing as jQuery support alteration of object properties via animate also, this is definitely fine.
var obj = {'test':0};
var interval = setInterval(function(){console.log(obj);}, 250);
$(obj).on("fun", function(){this.test++});
$(obj).animate(
{'test':100},
3000,
function (){
console.log(obj);
clearInterval(interval);
$(obj).trigger("fun")
console.log("increment",obj);
}
);
//will console log {test: 1.5}, {test: 6.4} etc then {test: 100}
//and finally "interval" {test: 101}
Quickredfox's backup comment is a pretty good source too: http://forum.jquery.com/topic/triggering-custom-events-on-js-objects