interface users {
s:number;
b:string;
}
function getPropertyName(propertyFunction: (a:users) => any) {
console.log(propertyFunction.toString()); // ii => ii.s > x && ii.s < 3
// how to read x variable here ?
}
(function() {
var x = 4;
getPropertyName(ii => ii.s > x && ii.s < 3);
})();
如何在getPropertyName函数中访问变量x?
答案 0 :(得分:1)
详细阐述Jeremy Starcher以代码答案形式所说的话。改变你的需求:
function test(func: (x:any, ii:any)=> any){
//do extra stuff here
}
var x, ii;
test(function (x, ii) {
//do stuff here
});