遍历对象man中的属性:
for (var i in man) {
if (man.hasOwnProperty(i)) { // 过滤,只显示属性,防止显示function
console.log(i, ":", man[i]);
}
}
防止man中定义了hasOwnProperty产生冲突:
var i, hasOwn = Object.prototype.hasOwnProperty;
for (i in man) {
if (hasOwn.call(man, i)) { // 过滤
console.log(i, ":", man[i]);
}
}