zoukankan      html  css  js  c++  java
  • function用es6怎么写

    1、普通函数的定义,用箭头函数表示,DemoFunction是函数名,括号表示参数,大括号表示函数体的内容。

    1
    2
    3
    let DemoFunc = (param) => {
        console.log(param)
    }

    2、map函数在es6中的写法,同样也是箭头函数,e表示map出来的元素,key表示当前id

    1
    2
    3
    Array.map((e, key) => {
        console.log(e, key)
    })

    3、类内函数的写法.

    1
    2
    3
    4
    5
    class FuncClass {
        myFunction(param) {
            console.log(param)
        }
    }

    4、thunk函数的写法,thunk代表一个中间函数,比如下面的例子,通常我们给函数传的参数是个value,但是thunk中,函数作为一个参数传给另外一个函数当参数。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    普通的写法:
    let DemoFunc = (value) => {
       return value
    }
    DemoFunc(value) //调用 
     
    thunk的写法:
    let valueFunc = () => {
       console.log(value)
    }
    let DemoFunc = (valueFunc) => {
       return valueFunc()
    }
  • 相关阅读:
    nuget
    C#枚举中使用Flags特性
    情感分析
    docker
    core部署
    脱壳系列_2_IAT加密壳_详细分析(含脚本)
    安全公司-* * * *-面试题:_ 安卓逆向分析分享
    18_ShadowWalker
    17_页面异常接管
    16_TLB与流水线
  • 原文地址:https://www.cnblogs.com/mgqworks/p/7735494.html
Copyright © 2011-2022 走看看