javascript - Function issues in ES6
伊谢尔伦
伊谢尔伦 2017-05-16 13:24:19
0
3
535
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,求大神告知
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
给我你的怀抱
var y = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ccas;//12
 这是一个三目运算,
arguments.length > 0 =》 false
arguments[0] !== undefined =》 false
所以就成了
=》
var y = false && false ? arguments[0] : ccas;
=》
var y = false ? arguments[0] : ccas;
不知道你是不理解三目运算还是?
值为true取值 : 前面的,false取值后面的。
所以y=12;
过去多啦不再A梦

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...

过去多啦不再A梦
var y = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ccas;//12

Because herey就是12

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template