I have a question about following code to print out "this.text".
I need to have a wrapper function to make it work. This is too troublesome.
Is there a simpler way (without additional wrapper) to get it work?
function Class1() {
this.text = "test";
}
Class1.prototype.show = function() {
console.log(this);
console.log(this.text);
}
var testClass = new Class1();
function funWithCallBack(cb) {
cb();
}
// it will show "undefined" because "this" scope changes to window
funWithCallBack(testClass.show);
function wrapper() {
testClass.show();
}
// this one will work but troublesome
funWithCallBack(wrapper)