原型链

作者: 稻草人_9ac7 | 来源:发表于2019-11-20 15:01 被阅读0次
    ////////////原来的js创建构造方法
    function Cat() { //构造器
        this.age = 20;
        this.name = "李白"
    
    }
    Cat.prototype.say = function() {
        console.log("name", this.name)
    }
    let cat = new Cat()
    cat.say() //name 李白
    
    //////////////es6创建构造方法
    class Dog {
        constructor() { //构造器
            this.name = "Dog";
            this.color = "白色";
        }
        say() {
            console.log("你是一只", this.name)
        }
    }
    let dog = new Dog()
    dog.say()
    

    相关文章

      网友评论

          本文标题:原型链

          本文链接:https://www.haomeiwen.com/subject/gdyoictx.html