: 注1:使用 fontSize 而不是 font-size 僅僅是爲了省去雙引號的麻煩
: 但如果你願意的話 "font-size" 的寫法也是可用的
: 注2:這一代碼在使用了污染 Object 原型的框架(比如 prototype)時將會失效
: 因爲 for (var-in) 語法將無法再得到乾淨的成員名
对于注2 不同意.
污染这词不好....
其实加上一点代码就可以解决问题了.
看一下这篇文章吧.
http://yuiblog.com/blog/2006/09/26/for-in-intrigue/
//部分摘录(好像连不上)
In all of the A Grade browsers, we should always write for in statements in this form:
for (name in obj) {
if (obj.hasOwnProperty(name)) {
...
}
}
It is deeply annoying that we have to include the extra if statement to filter out the extraneous values. It would seem better to ignore the flaw and code in ignorance. This is possible if you can guarantee that your code will never interact with programs that will augment Object.prototype. But as we get better at mashups and code sharing, ignorance produces brittleness. The standard describes an augmentable Object.prototype. Ignore standards at your own peril.
--
FROM 58.213.113.*