O'Reilly logo

JavaScript® Programmer's Reference by Alexei White

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Functions

At this stage, you will have encountered functions in the samples and discussions in earlier chapters. If you know another programming language, you are no doubt familiar with the concept. Like everything else, JavaScript does things just a bit differently from other languages, so if this describes you — don't worry; you'll probably learn something you didn't know.

The interesting thing about functions in JavaScript is that, compared to those of other languages, they are fairly limited in functionality — but at the same time there are some features that make them extremely powerful. For example, as you'll soon see, while you can't overload JavaScript functions in the traditional sense, you can change them on the fly and even create new ones after the program has begun running. The dynamic nature of JavaScript extends to the numerous ways in which you can deal with functions.

The Function Object

All functions in JavaScript are first class objects, meaning they can be passed around like any other object reference. In fact, regardless of how they are created, functions are instances of a global object named (aptly) Function. This means that every function in your code will have access to certain methods and properties, and can be treated like an object. In Appendix B I cover these methods and properties in considerable detail. For now, here is a quick reference. Remember that not all of these members are available in all JavaScript interpreters. See Appendix B for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required