zoukankan      html  css  js  c++  java
  • -_-#函数绑定

    addEventListener

    function Person() {
        this.init()
    }
    Person.prototype = {
        constructor: Person,
        init: function() {
            document.documentElement.addEventListener('click', this, false)
        },
        handleEvent: function(event) {
            this.say()
        },
        say: function() {
            alert('hello world!')
        }
    }
    
    var person = new Person()

    Function.prototype.bind

    function Person() {
        this.init()
    }
    Person.prototype = {
        constructor: Person,
        init: function() {
            document.documentElement.addEventListener('click', this.handleEvent.bind(this), false)
        },
        handleEvent: function(event) {
            console.log(event)
            console.log(this)
        }
    }
    
    var person = new Person()

    Function.prototype.bind Polyfill

    function bind(fn, context) {
        return function() {
            return fn.apply(context, arguments)
        }
    }
  • 相关阅读:
    2020-03-23
    2020-03-22
    2020-03-21
    2020-03-20
    2020-03-19
    2020-03-18
    2020-03-17
    单元测试-java
    2020-03-16
    C语言拯救计划Day3-1之求一批整数中出现最多的个位数字
  • 原文地址:https://www.cnblogs.com/jzm17173/p/3951252.html
Copyright © 2011-2022 走看看