Last active
August 24, 2016 06:46
-
-
Save kaiguogit/f591f8c5331eace1e0a10ee2454b3db3 to your computer and use it in GitHub Desktop.
Javascript scope question
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
1. | |
Q: A function doesn't have to return in order to be called a closure. Simply accessing variables outside of the immediate lexical scope creates a closure. | |
A: Nested functions, inner function access the outer function's variable. Then it's a closure, whether or not it return the variable to make it accessible outside. | |
2. | |
Q:function getMaxOfArray(numArray) { | |
return Math.max.apply(null, numArray); | |
} | |
A: This apply method takes an array as argument instead of argument list, so that we can use an array like object as argument. | |
getMaxOfArray([1,2,3]) instead of Math.max(1,2,3) | |
3. | |
Q: What is the purpose of the module pattern? | |
A: Modele parttern can create public method. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment