Last active
November 28, 2019 06:23
-
-
Save arccoza/d6209b4c7317a22f0e929808640b40a5 to your computer and use it in GitHub Desktop.
JavaScript Callable Object using bind
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 characters
'use strict' | |
class Callable extends Function { | |
constructor() { | |
super('...args', 'return this._bound._call(...args)') | |
// Or without the spread/rest operator: | |
// super('return this._bound._call.apply(this._bound, arguments)') | |
this._bound = this.bind(this) | |
return this._bound | |
} | |
_call(...args) { | |
console.log(this, args) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment