Prototype: Element.remove.bind (foo) not working as expected
I have this snippet:
self.puff({duration: 0, queue: 'end',
afterFinish: Element.remove.bindAsEventListener(self)
});
I am the element; it should remove the element from the document when all the effects on it are complete.
Unfortunately it won't work, otherwise "element.parentNode is undefined". If I replaced Element.remove.bindAsEventListener(self)
with function() { self.remove(); }
, then it will. I've tried just bind () with the same results.
The question is why is it not working and how do I use bind ()?
Bonus points for showing an easier way to remove an item after all the effects on it have been performed.
a source to share
self.puff({duration: 0, queue: 'end',
afterFinish: function () { self.remove(); }
});
What's wrong with that? You even suggest it yourself. You don't need to bind it as an event listener anyway, as this is just a syntactic version of the Prototype protocol bindings to ensure that the first parameter of the function is always the event object. Since afterFinish is not a browser event, this is optional.
Finally, you are linking the wrong function. You must bind an instance of the self method:
self.puff({duration: 0, queue: 'end',
afterFinish: self.remove.bind(self)
});
a source to share