Last active
August 29, 2015 14:05
-
-
Save elrrrrrrr/f411471f8c674f793eb3 to your computer and use it in GitHub Desktop.
javascript
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
var v='Hello World'; | |
(function(){ | |
alert(v); | |
var v='I love you'; | |
})() | |
var v='Hello World'; | |
(function(){ | |
var v; | |
alert(v); | |
v='I love you'; | |
})() | |
//结果是undefined | |
//scope | |
var x = 1; | |
console.log(x); // 1 | |
if (true) { | |
var x = 2; | |
console.log(x); //2 | |
} | |
console.log(x);// 2 | |
//建立临时scope | |
function foo() { | |
var x = 1; | |
if (x) { | |
(function () { | |
var x = 2; | |
// some other code | |
}()); | |
} | |
// x is still 1. | |
} |
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 ( condition ) { | |
function A () { | |
} | |
} | |
console.log(A) | |
//在火狐下不会预编译 |
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
//log = console.log 无效 | |
log = console.log.bind(console) |
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
function say667() { | |
// Local variable that ends up within closure | |
var num = 666; | |
var sayAlert = function() { alert(num); } | |
num++; | |
return sayAlert; | |
} | |
var sayAlert = say667(); | |
sayAlert()//执行结果应该弹出的667 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment