This file contains hidden or 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
| function init(args){ | |
| var firstName = args.firstName; | |
| var lastName = args.lastName; | |
| function gerunding(action){ | |
| return firstName + " " + lastName + " " + "is" + " " + action; | |
| } | |
| return gerunding; | |
| } | |
This file contains hidden or 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
| // We have two functions. One is named outie and the other is named closure *wink* *wink* | |
| //this is closure's global scope | |
| function outie(){ | |
| // this is closure's first and only outer scope | |
| function closure(){ | |
| // this is closure's local scope | |
| } | |
| } |
This file contains hidden or 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
| function sayMyName(firstName, middleName, lastName){ | |
| var praiseList = ["beautiful", "awesome", "splendid", "fantastic", "jaw-dropping"]; | |
| //this first closure called combineName() has access to the parameters | |
| //of the outer function and its variable | |
| function combineName(){ | |
| var min = 0; | |
| var max = praiseList.length - 1; | |
| //this second getRandomInt() closure has access to the variables in combineName() | |
| function getRandomInt(){ | |
| return Math.floor(Math.random() * (max - min) + min); |
This file contains hidden or 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
| $(document).ready(function(){ | |
| //It is important to notice that 'button' is a DOM object with various methods | |
| $('button').on('click', function(){ | |
| //We must preserve the button's context | |
| bluezy(); | |
| function bluezy(){ | |
| //We're saying, "I want to do fun things with <<that>> button object, | |
| //not <<this>> window object you keep giving me | |
| $(this).css("background-color", "blue"); | |
| }.bind(this) |
This file contains hidden or 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
| function firstFunc(){ | |
| var firstVar = 2; | |
| firstVar += secondVar; // secondVar is undefined because scope doesn’t look down | |
| function secondFunc(){ | |
| var secondVar = 5; | |
| } | |
| } |
This file contains hidden or 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
| var myHouse = { | |
| neighborhood: "Cherry Wood", | |
| address: "5 Premium Park", | |
| city: "Rolly", | |
| state: "NC", | |
| printInfo(){ | |
| // 'this' refers to the object we created. | |
| //'this' is easy to conceptualize here because... | |
| //we have manually created an object that we can see | |
| return this.neighborhood + "," + this.address + "," + this.city + "," + this.state |
This file contains hidden or 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
| $(document).ready(function(){ | |
| //It is important to notice that 'button' is a DOM object with various methods | |
| $('button').on('click', function(){ | |
| //We must preserve the button's context | |
| var that = this; | |
| bluezy(); | |
| function bluezy(){ | |
| //We're saying, "I want to do fun things with <<that>> button object, | |
| //not <<this>> window object you keep giving me |
NewerOlder