2011-05-04 59 views
0
function T() 
    { 
     var t = this; 
     function Hello() 
     { 
      alert(arguments.callee.caller == t);//false 
      alert(Hello.caller == t); //false 
      //this is a Object 
      //but caller just a Function. 
      //How? 
     } 

     Hello(); 
    }; 
    T(); 

// --------------------所以,我工作的代碼:但我不喜歡「property(this)」。所以...我需要像調用Object.How編碼?爲什麼javascript function.caller等於這個功能

function property(owner) 
{ 
    var that = this; 
    this.def = function (name, setFunction, getFunction) 
    { 
     Object.defineProperty(owner, name, { set: setFunction, get: getFunction }); 
     return that; 
    }; 
    this.propg = function (name, value) 
    { 
     Object.defineProperty(owner, name, 
     { 
      set: function (value) 
      { 
       ErrorLog(name + "並沒有實現屬性設置器。"); 
      } 
      , get: function() 
      { 
       return value; 
      } 
     }); 
     return that; 
    }; 
    this.prop = function (name, value) 
    { 
     var fieldValue = value; 
     Object.defineProperty(owner, name, 
     { 
      set: function (value) 
      { 
       fieldValue = value; 
      } 
      , get: function() 
      { 
       return fieldValue; 
      } 
     }); 
     return that; 
    }; 
    return that; 
} 

//#endregion 


using('Sofire.Data', function() 
{ 
    DataColumn = function (columnName, displayText) 
    { 
     var displayTextChanged = new EventObject(); 

     property(this) 
     .def('DisplayTextChanged' 
      , function (value) { displayTextChanged.Add(value); } 
      , function() { return displayTextChanged; }) 
     .propg('ColumnName', columnName) 
     .def('DisplayText' 
      , function (value) 
      { 
       displayText = value; 
       displayTextChanged.Raise(); 
      } 
      , function() { return displayText; }); 

    } 
}); 

回答

0

T是FunctionDeclaration,而t是被輸入T的ExecutionContext中時產生的電流ActivationObject

您將需要使用arguments.callee.caller == T才能獲得true

+0

哦,這就是爲什麼!但是,如何獲得調用者實例?! – TreenewLyn 2011-05-04 07:42:22

+0

em,你剛剛做了 - 'this' - 那*就是*實例 – 2011-05-04 07:52:54