美文网首页
bind call apply指向this和继承

bind call apply指向this和继承

作者: Chris__Liu | 来源:发表于2019-06-10 22:32 被阅读0次
    function father(name, age) {
        this.name = name
        this.age = age
    }

    function child(name, age, height) {
        // father.apply(this,arguments)
        father.call(this, name, age)
        this.height = height
        return "name:" + this.name + "  age:" + this.age + "  height:" + this.height
    }



    obj.hellow = function(){
        console.log(this)
        return 'hellow boy'
    }
    function hellow(){
        console.log(this)
        return 'hellow boy1'
    }

    btn1.onclick = function () {
        console.log(hellow.bind(this))
    }
image.png
image.png
image.png
image.png
image.png

相关文章

网友评论

      本文标题:bind call apply指向this和继承

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