var ccas = 12;
function ff() {
var a;
console.log(arguments.length);//0
console.log(arguments[0]);//undefine;
console.log(arguments.length > 0);//false
console.log(a = arguments.length > 0 && 1);//false
console.log(arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ccas);//12
var y = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ccas;//12
return function () {
console.log(arguments.length);
var ccas = 7;
console.log(y);
}.apply(null, arguments);
}
ff();
为什么y的值是12,求大神告知
Because arguments[0]==undefined
and var y = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ccas;//12
So y=12
If you want to ask why it is not equal to 7
You need to learn about closures, basic types and reference types
Reference link:
http://www.cnblogs.com/chengg...
http://www.ruanyifeng.com/blo...
Because here
y
就是12