I'm trying to learn how to write better javascript but I'm not sure why this doesn't work. I have two method calls that write to a text field. The first one works fine, but the second one doesn't. Why is the text field variable undefined going thorough a nested call? Any help would be appreciated:
(function () {
var TestObj = function (logEl) {
this.log = logEl;
};
TestObj.prototype = function () {
var log1 = function (text) {
this.log.val(text);
};
var log2 = function (text) {
log1(text);
}
return {
log1: log1,
log2: log2
};
}();
$(function () {
var logEl = $("#log");
var test = new TestObj(logEl);
test.log1("This Works");
test.log2("This Dosen't"); //this.log is undefined
});
})()