Skip to content

Instantly share code, notes, and snippets.

@fancyboynet
Created August 22, 2018 07:12
Show Gist options
  • Select an option

  • Save fancyboynet/d5785f87cf385035c634027c20d074f9 to your computer and use it in GitHub Desktop.

Select an option

Save fancyboynet/d5785f87cf385035c634027c20d074f9 to your computer and use it in GitHub Desktop.

Revisions

  1. fancyboynet revised this gist Aug 22, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion demo.js
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,6 @@ class Demo extends AutoBindMethod {
    hello () {
    console.log(this)
    }
    }
    }

    new Demo()
  2. fancyboynet created this gist Aug 22, 2018.
    17 changes: 17 additions & 0 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    class AutoBindMethod {
    constructor () {
    Object.getOwnPropertyNames(this.constructor.prototype).forEach(m => {
    this[m] = this[m].bind(this)
    })
    }
    }

    class Demo extends AutoBindMethod {
    constructor () {
    super()
    document.addEventListener('click', this.hello)
    }
    hello () {
    console.log(this)
    }
    }