Wielding Functions
This chapter covers anonymous, inline, recursive, and overloaded functions in JavaScript. Their overloading method is based on matching behavior to a number of arguments (I personally prefer a single object as an argument, then acting on the properties).
What I Learned in This Chapter:
Nothing was really new to me in this chapter, but an example of handling overloaded functions was interesting (the author created layers of anonymous functions that end up acting as a pseudo-recursion). There was an explanation of this method of identifying functions:
1 2 3 |
function isFunction(fn) { return Object.prototype.toString.call(fn) === "[object Function]"; } |
This is used to work around bugs/odd behaviors in Firefox, IE, and Safari where they will incorrectly report certain objects as functions. I hadn’t known about these…good to know!