JavaScript(ECMAScript5)严格模式是否具有明显的性能优势,值得广泛使用? [英] Does JavaScript (ECMAScript5) Strict Mode offer significant performance advantages to merit widespread use?

查看:65
本文介绍了JavaScript(ECMAScript5)严格模式是否具有明显的性能优势,值得广泛使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读针对JavaScript使用严格模式的知识,通常看来,这种想法是将一套更严格的规则强加给编码器,以确保JS引擎可以更好地优化代码。

I'm reading up a bit on using Strict Mode for JavaScript and it seems that, generally speaking, the idea is to force a more rigid set of rules onto the coder to ensure that the JS engine can optimise the code better. It almost feels like the JavaScript equivalent of "Option Explicit" in Visual Basic.

如果这基本上是将严格模式应用于我的代码的净效果,那么性能会有所不同吗?是否值得出于习惯而不是个案的应用?除了代码稳定性以外,还有其他值得考虑的优点吗?

If this is basically the net effect of applying Strict Mode to my code, would the performance difference be such that it would be worth applying out of habit rather than case-by-case? Are there other advantages besides code stability that might be worth considering?

我想对脚本应用严格模式的一些关键原因是什么?

What are some of the key reasons I would want to apply Strict Mode to my scripts?

推荐答案

严格模式代码当然可以表现更好,因为它消除了使优化变得更加困难的问题,例如,从我的头上来:

Well, strict mode code can certainly perform better because it removes issues that made optimization harder, for example, from the top of my head:


  • 已删除 with 语句(确实很困难-如果不是不可能的话,则无法对其进行优化)

  • 没有未声明的分配和其他禁止,例如(删除varName;

  • eval 不引入变量/函数声明

  • arguments.callee 被删除,(难以优化(例如,函数内联 ))

  • 参数对象索引的命名属性不再动态映射到命名的形式参数。

  • The with statement was removed (Really difficult -if not impossible- to optimize).
  • No more undeclared assignments, and other prohibitions, e.g. (delete varName;)
  • eval does not introduce variable/function declarations into the local scope.
  • arguments.callee was removed, (difficult to optimize (e.g. function inlining))
  • The arguments object index named properties are not anymore dynamically mapped to the named formal parameters.

这篇关于JavaScript(ECMAScript5)严格模式是否具有明显的性能优势,值得广泛使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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