三个知识点:对象建立、指针以及属性名、属性值列举
//this练习
function fun() {
console.log("此处所调用的对象为:" + this.name);
}
//两种建立对象方法练习
var obj1 = new Object();
obj1.name = "OBJ1";
obj1.sayName = fun;
var obj2 = {
name: "OBJ2",
age: 100,
gender: "male",
sayName: fun,
}
//函数练习、列举属性名和属性值练习
var show = function(obj) {
for (var n in obj) {
console.log(n + " = " + obj[n]);
}
};
obj1.sayName();
obj2.sayName();
show(obj2);
输出: