gpt4 book ai didi

javascript - 需要澄清 javascript 中的奇数双重赋值语法

转载 作者:行者123 更新时间:2023-11-30 08:46:02 25 4
gpt4 key购买 nike

我有以下代码:

var $scope, modelValue;
modelValue = $scope.model = {};

谁能解释一下这个双重赋值在 javascript 中的含义?

为什么需要第二次赋值?

最佳答案

这一行 modelValue = $scope.model = {}; 就像这样写:

$scope.model = {};
modelValue = $scope.model;

写表达式时:variable = expression,表达式先求值再赋值,所以这条语句是从右向左求值的:

variable = (variable = expression)//内部表达式

我找到了这个文档:http://msdn.microsoft.com/en-us/library/1w2h1k9x(v=vs.94).aspx :

The = operator behaves like other operators, so expressions that contain it have a value. This means that you can chain assignment operators as follows: j = k = l = 0. In this case j, k, and l equal zero.

关于javascript - 需要澄清 javascript 中的奇数双重赋值语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21966859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com