function User(name){
        this.name=name;
    }
    //对应左边的
    // 此方法是挂上show
    // User.prototype.show=function(){
    //     console.log(this.name);
    // }


    //对应右边的
    //此方法是是重新创建了一个property,所以需要加上constructor
    User.prototype={
        constructor:User,
        show(){
            console.log(this.name);

        }
    }

    let lisi =new User.prototype.constructor("lisi");
    lisi.show();

 

posted on 2022-01-28 14:12  weakup  阅读(38)  评论(0)    收藏  举报