我m使用JavaScript。聲明一個實例變量「this.variable」將工作,直到我的函數將返回一個對象。返回一個字符串,數字不影響它。在返回一個對象的情況下,實例變量不再工作,併成爲「未定義」。請你能幫助我!在一個函數的範圍(在http://jsfiddle.net/woko/vE4rq/2/最新版本的Firefox &鉻的下測試尋找一個樣品)Javascript:函數 - 返回一個對象將無效this.variable
function Funct() {
this.varfunc = "this ist a instance";
return false;
}
var f = new Funct();
console.log(f.varfunc);
function FunctReturnobj() {
this.varfunc = "this ist a instance + return an object";
return {};
}
var fr = new FunctReturnobj();
console.log(fr.varfunc)
非常感謝,我的解決方案!用return語句調用函數將不會作爲「構造函數」執行 – user1267459 2012-03-13 21:08:37