JavaScript中函数对象方法arguments

		/*
		 * 在调用函数时,浏览器每次都会传递进两个隐含参数
		 * 1.函数的上下文对象this
		 * 2.封装实参的对象arguments
		 * 		- arguments 是一个类数组对象,它也可以通过索引来操作数据,也可以获取长度
		 * 		- 在调用函数时,我们所传递实参都会在arguments中保存
		 * 		- 我们即使不定义形参,也可以通过arguments来调用实参
		 * 			arguments[0]表示第一个实参
		 * 			arguments[1]表示第二个实参
		 * 		- 它里边有一个属性叫callee
		 * 			这个属性对应一个函数对象,就是当前正在指向的函数的对象
		 * 
		 */
		
		function fun(a,b){
			console.log(arguments instanceof Array);
			console.log(Array.isArray(arguments));
			console.log(arguments.length);
			console.log(arguments[0]);
			console.log(arguments.callee == fun);//true
			
		}
		
		fun("hello",true);

输出结果;
[Web浏览器] “false” /初级教程08/03arguments.html (24)
[Web浏览器] “false” /初级教程08/03arguments.html (25)
[Web浏览器] “2” /初级教程08/03arguments.html (26)
[Web浏览器] “hello” /初级教程08/03arguments.html (27)
[Web浏览器] “true” /初级教程08/03arguments.html (28)

猜你喜欢

转载自blog.csdn.net/plannothing/article/details/107745304
今日推荐