标签:str 实现 return 一点 symbol length 上下 call 迭代
实例代码:
function f1(){
console.log(arguments[0]);
console.log(arguments[1]);
console.log(arguments[2]);
}
f1(12,23,45); //12 34 45
实例代码:
function f2(a,b){
arguments[0] = 10;
arguments[1] = 20;
return a + b;
}
console.log(f2(4,6)); //30
注意: 'use strict' 是开启严格模式
实例代码:
function f3(a,b){
'use strict';
arguments[0] = 10;
arguments[1] = 20;
return a + b;
}
console.log(f3(3,6)); //9
实例代码:
function f4(){
console.log(arguments.length);
}
f4(2,3,4,5); //4
f4(1); //1
f4(); //0
实例代码:
var arr = Array.prototype.slice.call(arguments);
console.log(typeof arr);
var arr2 = [];
for(var i = 0; i<arguments.length;i++){
arr2.push(arguments[i]);
}
console.log(typeof arr2);
实例代码:
var f5 = function(){
console.log(arguments.callee===f5); //true
console.log(arguments.callee===f6); //false
}
var f6;
f5(); //返回原函数,调用自身
实例代码:
function add(a, b) {
var realLen = arguments.length;
console.log("realLen:", arguments.length);
var len = add.length;
console.log("len:", add.length);
if (realLen == len) {
console.log('实参和形参个数一致');
} else {
console.log('实参和形参个数不一致');
}
};
add(11,22,33,44,66);
实例代码:
var sum = function(n) {
if(n == 1) {
return 1;
} else {
return n + arguments.callee(n-1);
}
}
console.log("sum =", sum(5));
实例代码:
function add() {
var len = arguments.length;
var sum = 0;
for (var i = 0; i < len; ++i) {
sum += arguments[i];
}
return sum;
};
add(11,22,33,44,66);
标签:str 实现 return 一点 symbol length 上下 call 迭代
原文地址:https://www.cnblogs.com/huangwenjietk/p/10850307.html