Created
August 22, 2018 07:12
-
-
Save fancyboynet/d5785f87cf385035c634027c20d074f9 to your computer and use it in GitHub Desktop.
Revisions
-
fancyboynet revised this gist
Aug 22, 2018 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,4 +14,6 @@ class Demo extends AutoBindMethod { hello () { console.log(this) } } new Demo() -
fancyboynet created this gist
Aug 22, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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) } }