fci
05-04-2005, 03:38 PM
i'm not sure if the title of the thread is a good description. meh.
<script type="text/javascript">
function my_object() {
var self = this;
this.my_method = function() {
for (var i=0; i<10; i++) {
setTimeout(function() { self.blah(i); }, 1000);
}
};
this.blah = function(i) {
document.getElementById('yeah').innerHTML += i + '<br/>';
};
}
window.onload = function() {
var obj = new my_object();
obj.my_method();
}
</script>
<div id="yeah"></div>
the desired output would be 0...9
i have setup something else for now which works in my current case.. but I've wanted to do something like the above before but I couldn't figure it out..
ahh! just figured it out while giving it my last shot.
function my_object() {
var self = this;
this.my_method = function() {
var x;
var test;
for (var i=0; i<10; i++) {
test = function() {
var x = i;
setTimeout(function() { self.blah(x); }, 100);
}
test();
}
};
this.blah = function(j) {
document.getElementById('yeah').innerHTML += j + '<br/>';
};
}
window.onload = function() {
var obj = new my_object();
obj.my_method();
}
</script>
<div id="yeah"></div>
thanks for looking at the thread .. i guess... feel free to post comments then..
<script type="text/javascript">
function my_object() {
var self = this;
this.my_method = function() {
for (var i=0; i<10; i++) {
setTimeout(function() { self.blah(i); }, 1000);
}
};
this.blah = function(i) {
document.getElementById('yeah').innerHTML += i + '<br/>';
};
}
window.onload = function() {
var obj = new my_object();
obj.my_method();
}
</script>
<div id="yeah"></div>
the desired output would be 0...9
i have setup something else for now which works in my current case.. but I've wanted to do something like the above before but I couldn't figure it out..
ahh! just figured it out while giving it my last shot.
function my_object() {
var self = this;
this.my_method = function() {
var x;
var test;
for (var i=0; i<10; i++) {
test = function() {
var x = i;
setTimeout(function() { self.blah(x); }, 100);
}
test();
}
};
this.blah = function(j) {
document.getElementById('yeah').innerHTML += j + '<br/>';
};
}
window.onload = function() {
var obj = new my_object();
obj.my_method();
}
</script>
<div id="yeah"></div>
thanks for looking at the thread .. i guess... feel free to post comments then..