You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the documentation, there's this note under the addEventListener section:
Note 1: you should pass a reference to a function as the listener argument, not an anonymous function. To remove the listener you just pass the same reference to the removeEventListener method. If you pass an anonymous function, you won't be able to unregister it: this behavior is similar to the unregistering of a DOM event listener (EventTarget.removeEventListener()).
I think there's a misunderstanding about what an anonymous function is. An anonymous function is just a function without a name, but an anonymous function can still be stored in a variable that can be referenced later. For example, this uses an anonymous function:
varadobeDataLayer=[];varaddToCartListener=function(){console.log("product added to cart");};adobeDataLayer.push(function(dl){dl.addEventListener("addToCart",addToCartListener);});setTimeout(function(){adobeDataLayer.push(function(dl){dl.removeEventListener("addToCart",addToCartListener);});},3000);
I think what the documentation is intending to say is that the developer needs to store a reference to the function if they would like to remove the event listener later. Whether that's done using a named function or an anonymous function doesn't really matter.
The text was updated successfully, but these errors were encountered:
Thanks again for this data layer!
In the documentation, there's this note under the
addEventListener
section:I think there's a misunderstanding about what an anonymous function is. An anonymous function is just a function without a name, but an anonymous function can still be stored in a variable that can be referenced later. For example, this uses an anonymous function:
I think what the documentation is intending to say is that the developer needs to store a reference to the function if they would like to remove the event listener later. Whether that's done using a named function or an anonymous function doesn't really matter.
The text was updated successfully, but these errors were encountered: