1
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에 액세스 할 수 있습니까 ??TypeScript, JavaScript 람다 변수에 액세스하는 방법
그렇게 할 수있는 방법은 없습니다. 왜 그걸하고 싶니? – Thomas
당신은 같은 범위에'x'와'getPropertyName'을 가져야합니다 .. 다른 범위, 접근 할 방법이 없습니다. 그것은 getPropertyName을 수정하거나 추가 인자를 취할 수 있습니다. –
나는 ORM이라고 쓰고 싶다 :) 그리고 그것은 어디에서 함수 인수가 좋을까 ... – Pasibrzuchon