是否有可能訪問只能在「with」語句內使用方括號表示法訪問的對象屬性。「與」範圍和屬性用方括號表示法
例子:
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',請 – 2010-06-06 21:59:05
''有它的用途,就像'goto'或'eval'一樣。我認爲通用[認爲有害](http://en.wikipedia.org/wiki/Considered_harmful)聲明比有問題的聲明更有害。 – Anurag 2010-06-06 22:06:54
@ M28我同意Anurag,JavaScript的美麗之一是它的多功能性。請參閱此帖http://stackoverflow.com/questions/61552/are-there-legitimate-uses-for-javascripts-with-statement。雖然它確實有它的危險。 'Javascript:道格拉斯克羅克福德的好作品'中的 – Laramie 2010-06-06 22:17:19