for in 语句可以遍历对象中所有的属性。枚举包括函数和原型属性。var fruit = { apple: 2, orange:5, pear:1},sentence = 'I have ',quantity;for (kind in fruit){ quantity = fruit[kind]; sentence += quantity+' '+kind+ (quantity===1?'':'s')+ ', ';} // The following line removes the trailing coma.
There are two ways to create an object in JavaScript:在Javascript中,有两种方法去创建一个 对象 :字面上 var object = {}; // 是的,简单是使用一对大括号!注意: 这是 推荐 的方法面向对象 var object = new Object();注意: 这很像Java