Created
June 29, 2014 04:23
-
-
Save zhanhongtao/08e8afed3d043bc93b41 to your computer and use it in GitHub Desktop.
形参和 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
// arguments 类数组和形参 | |
function $( selector, context ) { | |
// default | |
console.log( arguments ); // 'div' | |
console.log( selector, context ); // 'div', undefined | |
// 更新 selector | |
selector = 'p'; | |
console.log( arguments ); // 'p' | |
console.log( selector ); // 'p' | |
// 更新 context 变量. | |
context = context || document; | |
console.log( context ); // document | |
console.log( arguments ); // 'div' -> arguments 不变. | |
// 更新 arguments. | |
arguments[0] = 'div'; | |
arguments[1] = '_string'; | |
console.log( arguments ); // 'div', '_string' | |
console.log( selector, context ); // 'div', document | |
// 形参和实参个数 | |
console.log( arguments.length ); // 1 | |
console.log( $.length ); // 2 | |
} | |
$( 'div' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment