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此例无报错
- 不能用 with
function f() {
"use strict";
var o = { o: 0 };
with (o) {
}
}
f(); // SyntaxError: Strict mode code may not include a with statement
- arguments 不可改参数
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