Academic > Computer Science > Download, free read

Pro JavaScript Development by Den Odell download in iPad, ePub, pdf

You'll learn to use time-saving features like list comprehensions and splats, organize your code into modules with extensible classes, and see how to deploy your work to multiple environments. In short, a function call is passed a special value based upon the parent object it is called from. For many years, it was viewed simply as a scripting language. In this case, x is passed to the makeTimeout function. On the other hand, if you use the prototype instead, you only declare the function once and each instance uses the prototypal definition.

It can be the source of very annoying production defects if not handled properly. The last example demonstrates how to reuse a function in a different context. The distinction is subtle but necessary to ensure frameworks and developers have a consistent understanding of what it means. According to the specification, a function is essentially a member of the Object type that is an instance of the standard built-in Function constructor and that may be invoked as a subroutine. This is an anonymous function that is invoked right away.

You can deal with functions just like you would objects, as illustrated here. Every function has the potential to create new objects using the new operator. As you may be aware, the former compares type and value, while the latter will coerce types. This is subtle but important. Now that local parameter is in the makeTimeout scope for that call.

The bind function

The bind function is important to understand because it allows you to explicitly set the context of a method. When a property is accessed, it is first checked on the object, and barring that pardon the pun is referenced on the prototype. You can create some confusing behaviors if you think this is always the object the method is defined on. The anonymous function is used to wrap the call so a local instance of x is captured in the y parameter and the call will work as expected. This is more than just a cool trick.

When a property is accessed