如何獲取已綁定到函數的參數?如何獲取已被JavaScript的.bind()函數綁定的參數
function add(x){
return x + 1
}
var func = add.bind(null, x)
// how do I get the value of `x` from the `func` variable alone?
如何獲取已綁定到函數的參數?如何獲取已被JavaScript的.bind()函數綁定的參數
function add(x){
return x + 1
}
var func = add.bind(null, x)
// how do I get the value of `x` from the `func` variable alone?
var claser = function(x) {
var internalX = x;
this.add = function(adderValue) {
internalX += adderValue;
}
this.getX = function() {
return internalX;
}
}
var theX = 5; // Setting X
var cls = new claser(theX);
cls.add(1); // Adding X
var gettingX = cls.getX(); // Getting X
alert(gettingX);
這是你需要什麼?
你已經檢索到了變量,現在這個變量存儲在func中。這不是你想要的嗎? –
上面的代碼只是一個例子,我有'func'變量的上下文我沒有原始參數 – Rob
我認爲你不能。 – evolutionxbox