Consider the following JavaScript class, property, and method:
function Foo() {
this.data = 123;
}
Test.prototype.foo = function() {
$("body").append($("<div>")
.text("Hello World!")
.click(function () {
alert("Data: " + this.data);
})
);
}
var Bar = new Foo();
Bar.foo();
Why is the property data undefined in the alert box? How can "this" be referenced, as pointed to the Foo class and not the jQuery div element?