写法:

  1. 箭头函数:
  2. var show = ()=>{
  3. console.log("hello wold")
  4. }
  5. show() 只能在该函数后面调用
  6. 相当于:
  7. var show = function(){
  8. console.log("hello wold")
  9. }
  10. show() 只能在该函数后面调用

如果箭头函数中只有一段语句可以简写

  1. var show =()=>console.log("hello world!!");
  2. show()

带参数的箭头函数

  1. var go =x=>console.log(x); //一段语句可简写
  2. var sum =(x,y)=>{console.log(x+y)};
  3. go(2);
  4. sum(4,3);