This project is archived and is in readonly mode.

#1108 ✓duplicate
Nate

Repeatable Events.removeEvents calls can lead to "TypeError: undefined has no properties"

Reported by Nate | December 2nd, 2010 @ 08:25 PM | in 1.3.1 (closed)

For Mootools 1.3 Release, and verified with Firefox 3.6.12 and Safari 5.0.3 on Mac OS X 10.6.5

In Class.Extras, the Events.removeEvent uses javascript's "delete" syntax to remove functions from the $events[type] array. For arrays, "delete" will replace the value at an index with "undefined".

To illustrate:
var a = [1, 2, 3];
delete a[0]; // a is now ["undefined", 2, 3]

When calling Events.removeEvent on an object, its $events[type] array ends up containing an "undefined" value. So when Events.removeEvents is called on the same object, it iterates through all the functions (some of which are now "undefined") for a given handler and passes them on to removeEvent via the "fn" parameter. When removeEvent tries to access the "internal" property on "fn", an error is generated because "fn" is not an object.

Reproduce code: http://jsfiddle.net/UCJr4/1/

A possible fix could be to use Array.erase instead of "delete" in removeEvent. This would keep "undefined" from entering the $events[type] array at all. If deemed valid, I could try to submit a patch.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

People watching this ticket

Pages