17.11.2015 Views

JavaScript_Succinctly

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

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

Global functions contained within the head object<br />

<strong>JavaScript</strong> ships with some predefined functions. The following native functions are<br />

considered methods of the head object (e.g., in a web browser,<br />

window.parseInt('500')). You can think of these as ready-to-use functions and<br />

methods (of the head object) provided by <strong>JavaScript</strong>.<br />

decodeURI()<br />

decodeURIComponent()<br />

encodeURI()<br />

encodeURIComponent()<br />

eval()<br />

isFinite()<br />

isNaN()<br />

parseFloat()<br />

parseInt()<br />

The head object vs. global properties and global variables<br />

Do not confuse the head object with global properties or global variables contained<br />

within the global scope. The head object is an object that contains all objects. The term<br />

"global properties" or "global variables" is used to refer to values directly contained<br />

inside the head object and are not specifically scoped to other objects. These values<br />

are considered global because no matter where code is currently executing, in terms of<br />

scope, all code has access (via the scope chain) to these global properties and<br />

variables.<br />

In the following sample, I place a foo property in the global scope, then access this<br />

property from a different scope.<br />

Sample: sample65.html<br />

<br />

var foo = 'bar'; // foo is a global object and a property of the<br />

head/window object.<br />

var myApp = function () { // Remember functions create scope.<br />

var run = function () {<br />

79

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

Saved successfully!

Ooh no, something went wrong!