Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【20160926】JS问题规避 #23

Closed
zhongxia245 opened this issue Sep 27, 2016 · 0 comments
Closed

【20160926】JS问题规避 #23

zhongxia245 opened this issue Sep 27, 2016 · 0 comments
Labels

Comments

@zhongxia245
Copy link
Owner

zhongxia245 commented Sep 27, 2016

JS规范

有一些JavaScript的写法必须要规避。 开发尽量使用严格模式。IE10 以下不支持严格模式

  • 使用严格模式,规避一些常规错误
"use strict";
  • 变量声明提升导致的问题

    两个 name 会被提升到 作用域的最前面 ,在严格模式下, 重复定义一个变量名会报错。

SCRIPT1046:严格模式下不允许一个属性有多个定义

var testObj = {
    prop1: 10,
    prop2: 15,
    prop1: 20
};

这里有两个 prop1 属性, 在严格模式下报错

参考

  1. MSDN严格模式 (JavaScript)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant