Search the Community
Showing results for tags 'removeBetween'.
-
Hi, When I using the Group.removeBetween(startIndex) to remove children from startIndex to the end of the Group, it always throws Uncaught TypeError: Cannot read property 'events' of undefined.It seems that the implemention of default endIndex is bugged? : Group.js#line-1580 if (typeof endIndex === 'undefined') { endIndex = this.children.length; } Group.js#line-1594 var i = endIndex;while (i >= startIndex){ //The first children[i] is out of bounds? if (!silent && this.children[i].events) { this.children[i].events.onRemovedFromGroup.dispatch(this.children[i], this); } var removed = this.removeChild(this.children[i]);
- 1 reply
-
- removeBetween
- bug
-
(and 1 more)
Tagged with:
-
It is very awkward to say this, but for me it looks like current implementation of this function is bugged. Probably no one uses it anyway or it would be long found The thing is that the code falls in a very trivial trap: it changes the array it is iterating over: for (var i = startIndex; i < endIndex; i++) { if (this.children[i].events) { this.children[i].events.onRemovedFromGroup.dispatch(this.children[i], this); } this.removeChild(this.children[i]); if (this.cursor === this.children[i]) { this.cursor = null; } }removeChild line will shift the indexes, if I'm not mistaken. Eventually the loop fails on accessing .events for non-existant (out of bounds) child. Also it seems reasonable to make second parameter optional, just removing every item starting with startIndex.