http://jsfiddle.net/BkNfY/12/
function Test(){
var that = this;
that.yo = "YO";
that.go = function(){
alert(that.yo);
}
$(".aha").click(function(){
that.go();
});
return that;
}
var test = new Test();
but it would make more sense to do it like this: (if you want to reuse Test)
function Test(){
var that = this;
that.yo = "default YO";
that.go = function(){
alert(yo);
}
return that;
}
var test = new Test();
test.yo = "YO";
$(".aha").click(function(){
test.go();
});
You could keep yo "private" if it is not going to be used outside of Test, e.g. test.yo
function Test(){
var that = this,
yo = "YO"; // yo is now "private"
// so can't modify yo from outside of this function
that.go = function(){
alert(yo);
}
return that;
}
var test = new Test();
$(".aha").click(function(){
test.go();
});