events pointing at methods
Let's say I've got this function (don't be baffled as to what the point is; it's a very simplified variation on what I'm doing):
function message(s)
{
this.utterance = s;
this.yell = function(str)
{
alert(this.utterance);
}
}
I can then do:
var whee = new message('whee!');
and then when I do:
whee.yell();
I get an alert that says "whee!"
But if I want the onload event to point to whee.yell, why do I have to do this:
onload = function(){whee.yell();}
instead of this, which gives an alert of "undefined":
onload = whee.yell;
It's not a problem; I'm just curious why it's like that.
function message(s)
{
this.utterance = s;
this.yell = function(str)
{
alert(this.utterance);
}
}
I can then do:
var whee = new message('whee!');
and then when I do:
whee.yell();
I get an alert that says "whee!"
But if I want the onload event to point to whee.yell, why do I have to do this:
onload = function(){whee.yell();}
instead of this, which gives an alert of "undefined":
onload = whee.yell;
It's not a problem; I'm just curious why it's like that.
