gpt4 book ai didi

javascript - 我对几行代码 AngularJS 有一些疑问

转载 作者:行者123 更新时间:2023-11-29 21:15:56 25 4
gpt4 key购买 nike

在我工作的地方,我们有一个需要修改的 angularjs 项目,但我无法完全理解这段代码:

app.controller("complementsController", function($scope, $rootScope, $mdSidenav, $timeout, $localStorage, $window) {
$scope.storage = $localStorage;
$scope.arrayCubiert = $scope.storage.cocinaCubiert.split("-");
$scope.tipoCubiert = $scope.arrayCubiert[1];
$scope.return = function() {
$window.history.back()
};
$scope.configurations = [{
logo: "some-logo",
val: 1
}];
"CUE" != $scope.tipoCubiera && "CUF" != $scope.tipoCubiert && "CUS" != $scope.tipoCubiert || $scope.configurations.push({
logo: "fiss-logo",
val: 2
});
"CUE" == $scope.tipoCubiert && $scope.configurations.push({
logo: "grafett-essence",
val: 3
});
$scope.opcionTitle = "EhapeAL", $scope.opcionImg = [ ["EAL.png", "EhapeAL AL"] ];
$scope.opcionBtn = 1, $timeout(function() {
$mdSidenav("sidebar").toggle().then(function() {})
}, 500);

具体我不明白的是:

"CUE"!= $scope.tipoCubierta && "CUF"!= $scope.tipoCubierta && "CUS"!= $scope.tipoCubierta || $scope.configuraciones.push({ 标志:“菲索标志”, 值:2 }),

这是一种简写条件???如果是这样,就可以用“传统”方式制成。

最佳答案

来自 MDN 关于 logical opereator :

Short-circuit evaluation

As logical expressions are evaluated left to right, they are testedfor possible "short-circuit" evaluation using the following rules:

false && anything is short-circuit evaluated to false.

true || anything is short-circuit evaluated to true.

The rules of logic guarantee that these evaluations are always correct. Note that theanything part of the above expressions is not evaluated, so any sideeffects of doing so do not take effect.

所以上述代码的“传统”方式是:

if(!("CUE" != $scope.tipoCubierta && "CUF" != $scope.tipoCubierta && "CUS" != $scope.tipoCubierta)){
$scope.configuraciones.push({ logo: "fisso-logo", val: 2 })
}

关于javascript - 我对几行代码 AngularJS 有一些疑问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39402745/

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