new关键字创建对象
<script>
var aa = new Object();
aa.name = "andy";
console.log(aa.name);
</script>
字面量创建对象
<script>
var aa = {
name: "andy",
};
console.log(aa.name);
</script>
工厂模式创建对象(创造出来的对象与函数没有关联)
<script>
function create(name) {
var obj = new Object();
obj.name = name;
return obj;
}
var aa = create("andy");
console.log(aa.name);
</script>
构造函数创建对象(创造出来的对象与函数有关联)
<script>
function create(name) {
this.name = name;
}
var aa = new create("andy");
console.log(aa.name);
</script>
获取对象的属性值
<script>
function create(name) {
this.name = name;
}
var aa = new create("andy");
console.log(aa.name);
console.log(aa["name"]);
</script>