js call的继承方式,为什么删除call只通过new也是可以实现继承的?

    function Base() {

        this.name='name'

        this.age=18

    }

    Base.prototype={

        say() {

            alert('hi')

        },

        ex:'lucy'

    }

    function Student() {

        Base.call(this,arguments)//////  删除这句话也可以,为什么??????

        this.add='US'

    }

    Student.prototype=new Base()//只通过这个就行,那还要上面的call有什么用?

    

    let tom=new Student()

    tom.say()


开心每一天1111
浏览 519回答 3
3回答

陪伴而非守候

JS的继承有多种 有原型对象继承 有修改构造函数继承 ,
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript