1
我在JS下一個功能:JS /使用對象,定義功能外
function status(){
this.functionA = function(){}
//Some others function and fields
}
,我有另一個功能:
function create(root){
var server = libary(function (port) {
//Here some functions
});
var returnValue = {
current:status(),
cur:function(port){
current.functionA();
}}
return returnValue;
}
當我打電話current.functionA()
,它說,當前是未定義。我怎樣才能撥打functionA()
?
我按照你的說法嘗試,但它仍然給我,目前是未定義的 – user2450886
@ user2450886在''''裏面,你需要使用'this.current.functionA()',所以你引用'current'屬性'returnValue'。 (假設你調用'cur'作爲'returnValue'對象的一個方法,所以'this == returnValue')。 – apsillers
@apsillers:我使用這個,但現在它給了我下一個錯誤:無法調用方法FunctionA() undefined – user2450886