ns

notes

View on GitHub

EcmaScript5.1 新增语法

浏览器兼容: es5-shim

严格模式

某些非法操作被限制

function f() {
  "use strict";
  a = 3; // 隐式全局
  alert(a);
}
f(); // ReferenceError: a is not defined
function f() {
  "use strict";
  var o = {
    a: 1,
    a: 1
  };
}
f(); // chrome此例无报错
function f() {
  "use strict";
  var o = { o: 0 };
  with (o) {
  }
}
f(); // SyntaxError: Strict mode code may not include a with statement
function f(a) {
  arguments[0] = 98;
  console.log(a);
}
f(0); // 98

function f(a) {
  "use strict";
  arguments[0] = 98; // 静默失败
  console.log(a);
}
f(0); // 0

新增数组方法

Array.prototype.indexOf;
Array.prototype.lastIndexOf;
Array.prototype.every;
Array.prototype.some;
Array.prototype.forEach;
Array.prototype.map;
Array.prototype.filter;
Array.prototype.reduce;
Array.prototype.reduceRight;

Function.prototype.bind

改变this