總結ES5的一些一些規範 大家參考
例子寫的不是很完整 大家可以自己運行下 得出結果
進入嚴格模式
// ‘use strict‘;
// var b = 3;
// a = 4;
// alert(a);
一般環境在不添加識別也能識別
// 函數環境下
// a = 4;
// alert(4);
// function aaa() {
// ‘use strict‘;
// b = 6;
// b++;
// alert(b);
// }
// aaa();
// (function () {
// ‘use strict‘;
// var a = 4;
// a++;
// })();
// (function () {
// b = 5;
// b++;
// })();
/*‘use strict‘;
function sum(a, a, b) {
console.log(a, b);
}
sum(4, 7);*/
// ‘use strict‘;
// with(document) {
// alert(1);
// }
/*
function a() {
if(true) {
alert(‘你好‘);
} else {
alert(‘不好‘);
}
}
a();*/
/*
this的使用
1:在全局環境中或者普通函數中,this指向的是window對象
2:在對象的方法中,this指向的是方法的擁有者(對象)
*/
/*‘use strict‘;
console.log(this);
function hello() {
console.log(this);
}
hello();*/
/*var obj = {
say: function () {
console.log(this);
}
};
obj.say();*/
// bind:改變函數內部this的指向,返回值是一個內部this已經發生改變的新的函數
/*function sum(a, b) {
console.log(this);
console.log(a + b);
console.log(arguments);
}
var newSum = sum.bind(‘aaa‘, 6);
newSum(3, 4);*/
總結ES5的一些一些規範 大家參考