Skip to content

Instantly share code, notes, and snippets.

@arccoza
Last active November 28, 2019 06:23
Show Gist options
  • Save arccoza/d6209b4c7317a22f0e929808640b40a5 to your computer and use it in GitHub Desktop.
Save arccoza/d6209b4c7317a22f0e929808640b40a5 to your computer and use it in GitHub Desktop.
JavaScript Callable Object using bind
'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