Skip to Main Content
Professional, JavaScript® for Web Developers, Second Edition
book

Professional, JavaScript® for Web Developers, Second Edition

by Nicholas C. Zakas
January 2009
Intermediate to advanced content levelIntermediate to advanced
836 pages
21h 30m
English
Wrox
Content preview from Professional, JavaScript® for Web Developers, Second Edition

Chapter 18. Advanced Techniques

JavaScript is an incredibly flexible language that can be used in a variety of styles. Typically, JavaScript is used either in a procedural manner or an object-oriented one. The language, however, is capable of much more intricate and interesting patterns because of its dynamic nature. These techniques make use of ECMAScript language features, BOM extensions, and DOM functionality to achieve powerful results.

Advanced Functions

Functions are one of the most interesting parts of JavaScript. They can be quite simple and procedural in nature, or they can be quite complex and dynamic. Additional functionality can be achieved through the use of closures. Additionally, function pointers are very easy to work with, since all functions are objects. All of this makes JavaScript functions both interesting and powerful. The following sections outline some of the advanced ways that functions can be used in JavaScript.

Scope-Safe Constructors

Chapter 6 covered the definition and usage of constructors for defining custom objects. You'll recall that a constructor is simply a function that is called using the new operator. When used in this way, the this object used inside the constructor points to the newly created object instance, as in this example:

function Person(name, age, job){
    this.name = name;
    this.age = age;
    this.job = job;
}

var person = new Person("Nicholas", 29, "Software Engineer");

In this example, the Person constructor assigns three properties using the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional: JavaScript® for Web Developers, Third Edition

Professional: JavaScript® for Web Developers, Third Edition

Nicholas C. Zakas
JavaScript: Best Practice

JavaScript: Best Practice

James Kolce, Moritz Kroger, Ivan Curic, Samier Saeed, Jeff Mott, M. David Green, Craig Buckler

Publisher Resources

ISBN: 9780470227800Purchase book