Decorators and forwarding, call/apply thumbnail
Decorators and forwarding, call/apply
javascript.info
In the code above cachingDecorator is a decorator: a special function that takes another function and alters its behavior. Passing all arguments along with the context to another function is called call forwarding. And, when called like that, the function gets this = undefined. There’s a special bui
3 Users
0 Comments
37 Highlights
0 Notes

Top Highlights

  • In the code above cachingDecorator is a decorator: a special function that takes another function and alters its behavior.
  • Passing all arguments along with the context to another function is called call forwarding.
  • And, when called like that, the function gets this = undefined.
  • There’s a special built-in function method func.call(context, …args) that allows to call a function explicitly setting this.
  • The trick is called method borrowing.

Ready to highlight and find good content?

Glasp is a social web highlighter that people can highlight and organize quotes and thoughts from the web, and access other like-minded people’s learning.