Possible to enable “strict mode” in FireBug and Chrome's console?

前端 未结 5 820
刺人心
刺人心 2020-12-14 16:42

With this page:



  
    

        
相关标签:
5条回答
  • 2020-12-14 17:18

    On Chrome go to "chrome://flags", then "Enable Experimental JavaScript". Relaunch.

    0 讨论(0)
  • 2020-12-14 17:30

    If you are just testing a single function in the console, you can also just put 'use strict' as the first line in the function declaration.

    0 讨论(0)
  • 2020-12-14 17:30

    Chrome: put 'use strict'; prefix in your code line (and/or shift+enter for multiline)

    'use strict'; var foo = 2; delete foo;

    0 讨论(0)
  • 2020-12-14 17:31

    The firebug console works by wrapping all the code in an "eval" call so the first statement in your script is no longer "use strict" - hence it is disabled. You could try wrapping your code in a function to enforce "use strict" for that particular function but the best solution I know of is to skip the console and test straight in the page itself.

    0 讨论(0)
  • 2020-12-14 17:32

    use shift+enter to input 'use strict'

    like this

    0 讨论(0)
提交回复
热议问题