如果“如果”条件为假,语句不执行铬,但在Firefox执行 [英] If 'if' condition is false, statements do not execute in chrome, but execute in Firefox

查看:345
本文介绍了如果“如果”条件为假,语句不执行铬,但在Firefox执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的方案的plnkr。当我调试在Chrome code,声明中的第二个如果不执行。但是,当我调试它在Firefox中,在声明第二个如果被执行。

  angular.module('optionsExample',[])
  .controller('ExampleController',['$范围',函数($范围){
    调试器;
    如果属实){
        $ scope.name ='富';
    }
      如果(假){
        $ scope.name ='笑';
    }  }]);

火狐版本:35.0.1
Chrome版本:41.0.2272.101米

为什么会发生?

更新:

另外在Firefox 36.0.4测试,同样的问题。


解决方案

这可能是错误或者它可能只是他们是如何设计的。但是,这似乎与做如何调试涉及的if语句条件下,它可以很容易地评估,并使用code样式(K&安培; R,奥尔曼,1TBS等)

$ C $行C,可以有设置为他们断点绿色阴影,并且不能被调试器灰色阴影的。

简而言之调试if语句行(甚至其他控制语句行),它可以很容易地知道有一个真/假条件并不突出。当设置断点,断点将被放在code,而不是下一个断裂的线。

在使用1TBS / OTBS或K&功放块的情况下,R样式格式调试器将突出if块,而不是实际的if语句行中的第一个断裂的线。这使假IM pression里面假的条件code if语句将要执行的旁边

在使用奥尔曼风格格式化调试器将不突出,如果踩着语句或code座时通过的任何部分块的情况。如果你试图把一个code突破的if语句将跳过整个块,并把断点上的下一个断裂的线。

当if语句不使用条件如预期调试器可以很容易地理解为真/假调试器的行为。

示范测试

\r
\r

调试;\r
VAR 1 = TRUE;\r
VAR 2 = FALSE;\r
\r
//奥尔曼风格\r
如果(一个)\r
{\r
  的console.log(真理);\r
}\r
如果(二)\r
{\r
  的console.log(假);\r
}\r
\r
如果属实)\r
{\r
  的console.log(真理);\r
}\r
如果(假)\r
{\r
  的console.log(假);\r
}\r
\r
// 1TBS / OTBS风格\r
如果(一个){\r
   的console.log(真理);\r
}\r
如果(二){\r
   的console.log(假);\r
}\r
如果属实){\r
   的console.log(真理);\r
}\r
如果(假){\r
   的console.log(假);\r
}

\r

\r
\r

This is the plnkr of my scenario. When I debug this code in chrome, statement in second 'if' is not executed. But when I debug it in Firefox, the statement in second 'if' is executed.

angular.module('optionsExample', [])
  .controller('ExampleController', ['$scope', function($scope) {
    debugger;
    if(true){
        $scope.name = 'Foo';
    }
      if(false){
        $scope.name = 'lol';
    }

  }]);

Firefox version: 35.0.1 Chrome version: 41.0.2272.101 m

Why does it happen?

Update:

Also tested in Firefox 36.0.4, Same problem.

解决方案

This maybe a bug or it may just be how they designed it. But this seems to do with how the debugger deals with if statement conditions it can readily evaluate, and the code styling used (K&R, Allman, 1TBS, etc)

Lines of code that can have breakpoints set to them are shaded green, and ones that cannot are shaded gray by the debugger.

Simply put the debugger does not highlight if statement lines (and maybe even other control statement lines) that it can readily tell have a true/false condition. When setting a breakpoint the breakpoint will be put on the next breakable line of code instead.

In the case of blocks that use 1TBS/OTBS or K&R style formatting the debugger will highlight the first breakable line within the if block instead of the actual if statement line. This gives the false impression that the code inside false condition if statements are going to be executed next.

In the case of blocks that use Allman style formatting the debugger will not highlight any part of the if statement or code block when stepping through. And if you try to put a code break on the if statement it will skip the entire block and put the breakpoint on the next breakable line.

When the if statements do not use conditions that the debugger can readily read as true/false the debugger acts as expected.

Demo to test

debugger;
var one = true;
var two = false;

//Allman Style
if(one)
{
  console.log("Truth");   
}
if(two)
{
  console.log("false");   
}

if(true)
{
  console.log("Truth");   
}
if(false)
{
  console.log("false");   
}

//1TBS/OTBS Style
if(one){
   console.log("Truth");   
}
if(two){
   console.log("false");   
}
if(true){
   console.log("Truth");   
}
if(false){
   console.log("false");   
}

这篇关于如果“如果”条件为假,语句不执行铬,但在Firefox执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆