0

Hi
I have a loop looping through an "band" object array. I am assigning a anonymous functions for the object property(actually dragging)

for (var j=0;j<5;j++)
	{
		var othis = this.bands[j];
		othis.onDragstart = (function() {return othis.onDragstartResizeHandle()});
	}

onDragstartResizeHandle function

band.prototype.onDragstartResizeHandle = function()
{
  alert(this.id);
}

when I drag a band it always alert the id of 5th band. not the id of that band which i am currently refering. (even this is a anonymous function)
Cansomeone please tell me why?

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by chamika.deshan
0

othis.onDragstart = (function() {return othis.onDragstartResizeHandle()});

This is crazy. If i not travelling a loop and access objects one by one like

var othis1 = this.bands[0];
othis1 .onDragstart = (function() {return othis1 .onDragstartResizeHandle()});
var othis2 = this.bands[1];
othis2 .onDragstart = (function() {return othis2 .onDragstartResizeHandle()});

Now onDragstartResizeHandle function alert 2nd band id always. please help

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.