Book Image

Web Development with Jade

By : Sean Lang
Book Image

Web Development with Jade

By: Sean Lang

Overview of this book

Table of Contents (16 chapters)

The arguments object


Just as the arguments object is a local variable available in JavaScript objects, it is available in Jade mixins. In fact, it is used frequently in Jade to make mixins that accept a variable number of args, as shown in the following code snippet:

Jade

HTML

mixin list()
  ul
    - var args = Array.prototype.slice.call(arguments);
    for item in args
      li= item

+list('one', 'two', 'three')
<ul>
  <li>one</li>
  <li>two</li>
  <li>three</li>
</ul>

In the preceding example, we define a mixin (list) that appears to take no arguments, but in fact iterates over an array created from the arguments object. It is worth noting that we cannot iterate over arguments itself, because it is not a real array. Instead, we use - var args = Array.prototype.slice.call(arguments); to make an array called args from the arguments object.