This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The () suffix operator surrounding zero or more comma separated arguments. | |
The arguments in () passed to the function will be bound to the JS function pseudo parameter - parameters. | |
If a function is called with too many arguments, the extra arguments are ignored. | |
If a function is called with too few arguments, the missing values will be undefined. | |
There is no implicit type checking on the arguments. | |
There are 4 ways to call a function: | |
Function form | |
functionObject(arguments) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you using a function with an outside object, use this. | |
The this pseudo parameters contains a reference to the object of invocation. | |
this allows a method to know what object it is concerned with. | |
this allows a single function object to service many objects. | |
this is key to prototypal inheritance. | |
allows a single function to work on many objects | |
the way the function knows which object it is working on is by the this binding | |
this is a bonus parameter. Its value depends on the calling form. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All JS functions receive 2 pseudo parameters - arguments and this. | |
// The following uses JS built-in pseudo parameter (arguments). | |
// arguments is an array-like thing that contains all the arguments passed to the function | |
// if an argument changes, arguments also changes which can sometimes slow things down | |
// can access arguments.length | |
// and can use arguments to manipulate values passed to the function | |
function sum() { | |
'use strict'; | |
var i = 0, total = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
NewerOlder