对象的创建

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
//1, 创建对象 : 字面量创建对象
let str = 'name'
// let obj = {
//     [str]:"张三",
//     age:33,
//     hobby:function(){
//         console.log(333)
//     }
// }
// console.log(obj)

//2, 创建对象 构造函数
// let obj = new Object();
// obj.name = "张珊";
// obj.age = 22;
// obj.hobby = function(){
//     console.log("like background")
// }
// console.log(obj)

// 3, 属性方法放到原型上
// Object.create();
let obj = Object.create({
    name:"张三",
    age:40,
    hobby(){
        console.log("喜欢足球")
    }
})


</script>
</html>
posted @ 2020-03-26 11:58  Steven徐  阅读(106)  评论(0)    收藏  举报