参考:https://www.runoob.com/w3cnote/es6-function.html
一、赋值:
1、const { content } = this.props 等同于 const { content } = this.props.content
2、let obj = {a:1,b:2,c:3};
const {b} = obj;
console.log(b) 结果为:2
const {AA,BB,CC,...}=this.props;这里的是es6的一个方法来的,this.props={AA:'AA值',BB:'BB值',CC:'CC值',..},这个方法比较方便初始化变量,可以一次性赋值多个变量,const { content } = this.props.content可以变成
const content = this.props.content,不要花括号{}
3 函数
function fn(name,age=17){
console.log(name+","+age);
}
fn("Amy",18); // Amy,18
fn("Amy",""); // Amy,
fn("Amy"); // Amy,17
不定参数: ...变量名 并且有且只有一个不定参数。
function f(...values){
console.log(values.length);
}
f(1,2); //2
f(1,2,3,4); //4
箭头函数:
参数 => 函数体
var f = v => v;
//等价于
var f = function(a){
return a;
}
f(1); //1
多个参数,使用()括起来
var f = (a,b) => a+b; f(6,2); //8
当箭头函数函数体有多行语句,用 {} 包裹起来,表示代码块,当只有一行语句,并且需要返回结果时,可以省略 {} , 结果会自动返回。
var f = (a,b) => {
let result = a+b;
return result;
}
f(6,2); // 8
当箭头函数要返回对象的时候,为了区分于代码块,要用 () 将对象包裹起来
// 不报错
var f = (id,name) => ({id: id, name: name});
f(6,2); // {id: 6, name: 2}
注意点:没有 this、super、arguments 和 new.target 绑定。
var func = () => {
// 箭头函数里面没有 this 对象,
// 此时的 this 是外层的 this 对象,即 Window
console.log(this)
}
func(55) // Window
var func = () => {
console.log(arguments)
}
func(55); // ReferenceError: arguments is not defined
4、内部函数之间的调用
使用 this.方法
export default class Tes{
public tes1111() {
this.exportExcel();
}
public exportExcel() {
}
}