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.

Function object instance properties and methods<br />

Function object instances have the following properties and methods (not including<br />

inherited properties and methods):<br />

Instance Properties (e.g., var myFunction = function(x, y, z) {};<br />

myFunction.length;):<br />

arguments<br />

constructor<br />

length<br />

Instance Methods (e.g., var myFunction = function(x, y, z) {};<br />

myFunction.toString();):<br />

apply()<br />

call()<br />

toString()<br />

Functions always return a value<br />

While it’s possible to create a function simply to execute code statements, it’s also very<br />

common for a function to return a value. In the following sample, we are returning a<br />

string from the sayHi function.<br />

Sample: sample78.html<br />

<br />

var sayHi = function () {<br />

return 'Hi';<br />

};<br />

console.log(sayHi()); // Logs "Hi".<br />

<br />

If a function does not specify a return value, undefined is returned. In the following<br />

sample, we call the yelp function which logs the string 'yelp' to the console without<br />

explicitly returning a value.<br />

91

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

Saved successfully!

Ooh no, something went wrong!