JS Object的用法

读取属性的方法记一下

//js object的写法
    const person = {
        firstName: "John",
        lastName: "Doe",
        age: 50,
        eyeColor: "blue",
        fullName: function () {
            return this.firstName + " " + this.lastName;
        }
    };
    //获取object的属性方法
    //法一:
    console.log("法一:",person.firstName);
    //法二:
    console.log("法二:",person["firstName"]);

 

posted @ 2024-08-15 18:17  katesharing  阅读(6)  评论(0编辑  收藏  举报