Can someone please explain the following behavior? The first 2 examples work as expected, but why doesn't the last example work? I want to understand what's going on when I omit the 'this' keyword. It seems like I was able to omit it in the first 2 examples.
Alerts hello:
$(document).ready(
function()
{
hello = 'hello';
function sayHello()
{
alert( this.hello );
}
sayHello();
}
);
Alerts hello:
$(document).ready(
function()
{
hello = 'hello';
function sayHello()
{
alert( hello );
}
sayHello();
}
);
Error on the alert statement: Uncaught ReferenceError: hello is not defined
$(document).ready(
function()
{
this.hello = 'hello';
function sayHello()
{
alert( hello );
}
sayHello();
}
);