// 1. 创建对象 var stu = new Object(); stu.name = '张三'; stu.age = 18; stu.showInfo = function(){ console.log('姓名:' + this.name); console.log('年龄:' + this.age); }; stu.showInfo(); // 2. 字面量 创建对象 var cat = { name : '加肥', age : 4, showInfo : function(){ console.log('姓名:' + this.name); console.log('年龄:' + this.age); } }; cat.showInfo();