Company
Date Published
Author
Ben Vinegar
Word count
1847
Language
English
Hacker News points
None

Summary

In this article, function wrapping in JavaScript is discussed as a common practice used in various scenarios such as binding `this`, profiling, mixins, code coverage, hiding complexity, cross-platform code, and partial applications. Writing bulletproof function wrappers is crucial to ensure they can wrap any conceivable function without breaking anything. Key points include using `apply` and `arguments` when writing function wrappers, preserving arity by redeclaring variables, and considering the impact of function wrapper implementation on code that inspects a function's length property. The article emphasizes the importance of safeguarding against problematic behavior when writing function wrappers, especially for library authors or scripts operating in unknown environments.