今日份的学习
1.函数提升优先于变量提升2.函数名与变量名相同,如果变量没有赋值,不会覆盖函数
3.g是只读的, g只能在函数内部访问
var s = function g() {}
4.this谁调用指向谁,没人调用指向window
5.当函数被创建时,this指向当前函数的实例
6.ES6简单的函数声明不能被 new
var s = {
a:function () {
console.log(1);
},
b () {
console.log(2);
}
};
var f = s.a.bind(this);
new f();
//实例化时this指向这个实例,bind失效
var p = s.b.bind(this);
new p(); // 报错,不能实例化
7.window.length 为iframe的个数
8.不同浏览器不同的结果
function test() {
console.log(1);
};
(function () {
if (false) {
function test() {
console.log(2);
}
}
test();
})()
较新的浏览器等同于
function test() {
console.log(1);
};
(function () {
var test;// IE浏览器会提升整个函数
if (false) {
function test() {
console.log(2);
}
}
test();
})()
会报错(is not function)
9.对象与闭包在一起必须有分号
10.输出为undefined
function test(a) {
this.a = a;
}
test.prototype.a = 20;
test.prototype.init = function () {
console.log(this.a)
};
var s = new test();
s.init(); //原型链上有a,实例上也有a但没有传值,实例的优先级高于原型链,输出为undefined
11.TDZ 暂时性死区