Skip to content

Instantly share code, notes, and snippets.

@zhanhongtao
Created June 29, 2014 04:23
Show Gist options
  • Save zhanhongtao/08e8afed3d043bc93b41 to your computer and use it in GitHub Desktop.
Save zhanhongtao/08e8afed3d043bc93b41 to your computer and use it in GitHub Desktop.
形参和 arguments
// 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