While using javascript, I encountered an issue with instance variables. Declaring a variable as "this.variable" works fine until my function returns an object. However, if the function returns a String or Number, there are no issues. But when it returns an object, the instance variable becomes "undefined". Can anyone help me with this problem? (Check out a sample at http://jsfiddle.net/woko/vE4rq/2/ tested on recent versions of firefox & chrome)
function Funct() {
this.varfunc = "this is an instance";
return false;
}
var f = new Funct();
console.log(f.varfunc);
function FunctReturnobj() {
this.varfunc = "this is an instance + returning an object";
return {};
}
var fr = new FunctReturnobj();
console.log(fr.varfunc)