04.11.2015 Views

javascript

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5: Reference Types<br />

Pattern Limitations<br />

Although ECMAScript ’ s regular-expression support is fully developed, it does lack some of the advanced<br />

regular-expression features available in languages such as Perl. The following features are not supported<br />

in ECMAScript regular expressions (for more information, see www.regular - expressions.info ):<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

❑<br />

The \A and \Z anchors (matching the start or end of a string, respectively)<br />

Lookbehinds<br />

Union and intersection classes<br />

Atomic grouping<br />

Unicode support (except for matching a single character at a time)<br />

Named capturing groups<br />

The s (single- line) and x (free- spacing) matching modes<br />

Conditionals<br />

Regular - expression comments<br />

Despite these limitations, ECMAScript ’ s regular - expression support is powerful enough for doing most<br />

pattern - matching tasks.<br />

The Function Type<br />

Some of the most interesting parts of ECMAScript are its functions, primarily because functions actually<br />

are objects. Each function is an instance of the Function type that has properties and methods just like<br />

any other reference type. Because functions are objects, function names are simply pointers to function<br />

objects and are not necessarily tied to the function itself. Functions are typically defined using function -<br />

declaration syntax, as in this example:<br />

function sum (num1, num2) {<br />

return num1 + num2;<br />

}<br />

This is almost exactly equivalent to using a function expression, such as this:<br />

var sum = function(num1, num2){<br />

return num1 + num2;<br />

};<br />

In this code, a variable sum is defined and initialized to be a function. Note that there is no name<br />

included after the function keyword because it ’ s not needed — the function can be referenced by the<br />

variable sum . Also note that there is a semicolon after the end of the function, just as there would be after<br />

any variable initialization.<br />

122

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!