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();
// --------------------所以,我工作代码:但我不喜欢“属性(这个)”。所以......我需要像调用者Object.How编码?
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 :(得分:0)
T
是一个FunctionDeclaration,而t
是输入T的ExecutionContext时产生的当前ActivationObject
。
您需要使用arguments.callee.caller == T
才能获得true
。