账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    js连等赋值分析
    57
    0
    <script>
        var a = {n:1};
        a.x = a = {n:2};
        console.log(a.x);   //undefined
        var b = {n:1};
        b = b.x = {n:2};
        console.log(b);     //object{n:2}
        console.log(b.x);   //undefined
    </script>

    三个输出是什么原理?谢谢

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • ┽→僞╬鎻╬ 普通会员 1楼

      在JavaScript中,函数表达式、参数、变量和返回值的赋值可以按照等价关系进行分析。以下是一些常见的等价关系:

      1. 函数表达式赋值等价于函数调用: ```javascript function add(x, y) { return x + y; }

      var result = add(2, 3); // result === 5 ```

      1. 参数赋值等价于函数调用: ```javascript function add(x, y) { return x + y; }

      var result = add(2, 3); // result === 5 ```

      1. 变量赋值等价于函数调用: ```javascript var num1 = 2; var num2 = 3;

      var result = num1 + num2; // result === 5 ```

      1. 返回值赋值等价于函数调用: ```javascript function add(x, y) { return x + y; }

      var result = add(2, 3); // result === 5 ```

      在上述代码中,函数表达式、参数、变量和返回值的赋值等价于函数的调用。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部