定义
call()、apply()、bind()这三者都是用来重新定义this这个对象的
从下面的代码中可以看出,默认obj.myFun()和shows()中的this分别指向obj对象和Window对象。通过call()、apply()、bind()将this指向了db;
1 | var name = '小往', age = 17; |
call()、apply()、bind()这三者都是用来重新定义this这个对象的
从下面的代码中可以看出,默认obj.myFun()和shows()中的this分别指向obj对象和Window对象。通过call()、apply()、bind()将this指向了db;
1 | var name = '小往', age = 17; |
使用带有class关键字的类名
提升
函数声明会提升,类声明不会。你首先需要声明你的类,然后访问它,否则像下面的代码会抛出一个 ReferenceError:
1 | let p = new Rectangle(); // ReferenceError |
1 | // 匿名类 |
1 | isRequestAnimationFrame() { |
1 | // start-end-setTimeout |
1 | // start-promise1-promise2-end-then-setTimeout |
1 | // start async2-1-1 async2-2-1 end async2-1-2 |
在 JavaScript 中,除了 5 种原始数据类型之外,其他所有的都是对象,包括函数(Function)。
基本数据类型:String,boolean,Number,Undefined, Null
引用数据类型:Object(Array,Date,RegExp,Function)
圆周率,一个圆的周长和直径之比,约等于 3.14159.
1 | Math.PI; //Expected 3.141592653589793, got 3.141592653589793 |