javascript - removeEventListener with Unique Anonymous Function -
I have an object that generates HTML elements that are also associated with an array of objects, and we It says that we have one example of this as it creates this element, it provides the following event listener to a nested part of the element (class uploading).
Now the event listener must call the method of removing the example of the object that it was created, with the value of it I assigned to my creation. Because the events are under the window, for example an unknown function must be passed along with the I value.
This is why it provides a very unique function for the event, and because the removal method will destroy the element in which the listener is involved. I want to delete it first; I may leak from what I have read otherwise (?) I am also using the strict mode, hence the argument is not. Therefore I have tried many different things, but when I started an anonymous function within a function within the function which is called in the listener, I thought that only me Should ask here I may have a solution to the overall problem, the other code is changing, but it also helps when it can be answered. I'm doing this with help from Nordgard's answer. Since the specificity was attached to the object called file, I created a new property of the file to store the function: A deleted function that is called, then the event removes the listener. A relatively-painless way of doing this may be to create an object in that object Responsible for connecting and removing listeners, which creates an ID, serial or non, and the listener is in an object, the ID, whatever the object / module has requested it (or the anonymous function returns them back To return the id). Examples include listener = {}, i = 0, add = function reference, function, closer) {var attribute = (function (closure) {return function ()} {/ * ... * /; func ();}}}} (closure), index = i; Context.addEventListener ("...", attached, incorrect); Listeners [index] = enclosed; I + = 1; Return index; }; So now when you remove the stuff, you can just see the function saved on An alternative, if you do not want to fill a table in one of these places, for some reason, the return statement will be captured, and instead of returning to So now, when it's time to destroy everything, and you want to close your listener ... All that said, what you've read is still possible, but the main culprit was IE 6/7 (and earlier). Browsers, it becomes less important.
file.display.getElementsByClassName ('uploadDelete') [0] .addEventListener ('click', (function (that, i) {return function () {that.delete (i) ;};}) (This, I), false);
file.deleteFunction = (function (he, i) {return function ( ) {That.delete (i);};}) (this, i); File.display.getElementsByClassName ('Delete Upload') [0] .addEventListener ('Click', file.deleteFunction, false);
addition will now add to your listener, but you will also store the function that you are passing in the addEventListener in the
listener object . If you need a reference of
i , you have already closed it, if you want it.
the listener [i] .
i Come back to the function;
// Inside your module // I am not usually mad about `this`, without doing anything special, but hopefully this is my point Indicates this.cached_func = add (this.el, this.callback.bind (this), this.secret);
Remove
(this. Cached_func);
In fact, encouraging memory-dump in IE6 is probably a good way to encourage people not to use IE6.
Comments
Post a Comment