"with"문 안에있을 때 대괄호 표기법으로 만 액세스 할 수있는 개체 속성에 액세스 할 수 있습니까?"with"범위 및 특성 대괄호 표기법 사용
예 :
나는 특성이 자신의 이름으로 액세스 할 수 있도록 기본적으로, 오의 범위로 이동합니다 (O)로 알고있는 것처럼var o = { "bad-property": 1, "another:bad:property": 2, "goodProperty": 3 };
with(o) {
console.log(goodProperty); // works awesome
console.log(???) // how to access "bad:property"?
}
'with'로 끝내십시오. PLEASE –
'with'는'goto' 나'eval'처럼 사용합니다. 제네릭 [유해한 것으로 간주] (http://en.wikipedia.org/wiki/Considered_harmful) 진술은 문제의 것보다 더 해롭다 고 생각합니다. – Anurag
@ M28 나는 Anurag에 동의합니다. JavaScript의 아름다움 중 하나는 다재다능합니다. 이 게시물 http://stackoverflow.com/questions/61552/are-there-legitimate-uses-for-javascripts-with-statement를 참조하십시오. 그것은 위험을 가지고 있지만. – Laramie