-
ES6双冒号: 我们知道箭头函数可以自动绑定this对象,大大减少了显式绑定this对象的写法(call,apply,bind)。但是,箭头函数并不适用于所有场合,所以现在有一个提案,提出了函数绑定运算符,用来取代call,apply,bind。
foo::bar; // 等同于 bar.bind(foo); foo::bar(...arguments); // 等同于 bar.apply(foo, arguments);如果双冒号左边为空,右边是一个对象的方法,则等于将该方法绑定在该对象上面。
var method = obj::obj.foo; // 等同于 var method = ::obj.foo; let log = ::console.log; // 等同于 var log = console.log.bind(console); -
typeof中的圆括号为可选项,例如我们可以这样
typeof selectedBar==='undifined' -
ES6的对象结构:例如
const school={teacher:4,stu:600},那么我们之前一般会这样const teacher=school.teacher,用ES6可以用const {teacher,stu}=school -
parseInt函数的第二个参数表示转换为多少进制,例如:
<script>
console.log(parseInt('010',10)); // 输出10
console.log(parseInt('010',8)); // 输出8
console.log(parseInt('0x10',10)); // 输出0
console.log(parseInt('0x10',16)); // 输出16
</script>
- 在react中,constructor是用来构造分类的,这是ES6对类的默认方法,该方法是类中必须有的,如果没有,则会默认添加空的constructor( )方法。
class Point {
}
// 相当于
class Point {
constructor() {}
}
在class方法中,如果不调用super方法,子类就得不到this对象。另外对于super和super(props)的区别就是你是否需要在构造函数内使用this.props,如果需要那么你就必须要写props,如果不需要,写不写的效果是一样的。