Is strict mode more performant?

前端 未结 4 488
你的背包
你的背包 2020-11-30 02:50

Does executing javascript within a browser in \'strict mode\' make it more performant, in general? Do any of the major browsers do additional optimisation or use any other t

4条回答
  •  暖寄归人
    2020-11-30 03:30

    The strict mode is not really about performance, it a strict variant of the language, its main goal is to avoid what are considered to be error-prone features.

    Basically its goal is to make the language safer, introducing are a lot of semantical changes, also additional error checking is made, and erros are noisy, in non-strict code things only silently fail.

    About performance, I think browser vendors are now having a hard time now implementing strict mode, the problem is that the JS engines are mostly based on ECMAScript 3, and implementing the strict mode is not easy, since the scope of strictness is very flexible, you can mix non-strict and strict code.

    See also:

    • ECMAScript 5 Strict Mode, JSON, and More
    • SpiderMonkey strict mode ticket
    • Webkit strict mode ticket

提交回复
热议问题