Cover by John Resig and Bear Bibeault

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

O'Reilly logo

Chapter 10. With statements

This chapter covers

  • Why the with statement is controversial
  • How with statements work
  • Code simplification with with
  • Tricky with gotchas
  • Templating with with

The with statement is a powerful, frequently misunderstood, and controversial feature of JavaScript. A with statement allows us to put all the properties of an object within the current scope, allowing us to reference and assign to them without having to prefix them with a reference to their owning object.

It’s important to know that this statement’s continued existence within JavaScript is fleeting. The ECMAScript 5 specification prohibits its use in strict mode, to the extent of considering it a syntax error.

Moreover, the with statement, even prior to ...

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