步步为营之JavaScript

JS-类

2020-06-21  本文已影响0人  刘淘
{
    class User {
        constructor(name, age) {
            this.name = name
            this.age = age
        }
        show() {
            console.log(`${this.name} is ${this.age} years old`)
        }
    }
    const user = new User('xiamu', 18)
    console.log(typeof User)
    console.dir(User)
    console.log(User === User.prototype.constructor)
    console.dir(User)
    console.log(Object.getOwnPropertyNames(User))
    console.log(Object.getOwnPropertyNames(User.prototype))
    console.log(Object.getOwnPropertyDescriptor(User.prototype, 'show'))
}

image.png
上一篇 下一篇

猜你喜欢

热点阅读