events - JavaScript reference to anonymous function from inside that function -
i'm creating small canvas library in have anonymous function needs reference itself. however, don't know how this. have following incomplete code:
var removedraghandler = (function (object) { return function (e) { if (typeof object["dragend"] === "function") { object["dragend"](e); } removeevent({ element: window, event: "mousemove", callback: object["drag"] }); removeevent({ element: window, event: "mouseup", callback: ????? //what here? }); }; })(object); addevent({ element: window, event: "mouseup", callback: removedraghandler }); of course replace ????? arguments.callee, doesn't work in strict mode. there other options?
you can give name anonymous function. note there bug in older ie anonymous function leaks declared function in outer scope should not issue here since outer scope pretty empty anyway.
var removedraghandler = (function (object) { return function once(e) { if (typeof object["dragend"] === "function") { object["dragend"](e); } removeevent({ element: window, event: "mousemove", callback: object["drag"] }); removeevent({ element: window, event: "mouseup", callback: once }); }; })(object);
Comments
Post a Comment