javascript - How can I pass a handler function that may not be defined yet or may change at some point? -
i ask question because feel there cleaner way solve problem using anonymous function wrap call.
// not work because passes value found // @ obj.init @ time of binding. scope.on('anevent', obj.init); // works because wrapped in anonymous function , // obj.init method gets run whatever defined as. scope.on('anevent', function() { obj.init(); });
i want date method (obj.init) called whenever 'anevent' emitted.
you're not binding variables, you're binding values. raw obj.init
bind the value @ moment event handler. can't bind "the variable" , have value re-evaluated later. re-evaluate variable @ time of event firing, indeed straight forward option:
scope.on('anevent', function() { obj.init(); });
Comments
Post a Comment