Last active
October 4, 2015 14:27
-
-
Save StuPig/2652465 to your computer and use it in GitHub Desktop.
JS 的 作用域 作用域链 行参 实参 传值 而非 传址
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 a() { | |
// some operations | |
} // #1: 到这里会报错吗? | |
*/ | |
// a(); // #2: 到这里会报错吗? | |
// 执行到#1 时不会报错 | |
// 执行到#2 时会报错 | |
// 为什么? | |
// 因为JS 是一种解释行语言, | |
var a = 1 | |
, obj = {a: 'a'} | |
function num(a) { | |
// var a; | |
a = 10; | |
} | |
function ob(obj) { | |
// var obj; | |
obj = {a: 'b'} | |
// obj.a = 'b'; | |
} | |
num(a); | |
ob(obj); | |
console.log(a); // 1 | |
console.log(obj); // {a: 'a'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment