zoukankan      html  css  js  c++  java
  • 箭头函数如何使用

    function add(a,b){

    return a+b

    }

    箭头函数的写法:

    (a,b)=>{

    return a+b

    }

    如用箭头函数进行数组的升序和降序

    let arr = [10, 20, 1, 2];

    arr.sort((x,y)=>{

    return (y-x)

    })

    Console.log(arr);//[20,10,2,1]

    arr.sort((x, y) => {

     return(x-y)

    });

    console.log(arr); // [1, 2, 10, 20]

    使用箭头函数注意:

    • 没有this、super、arguments、newtarget绑定,箭头函数中的this、super、arrgument以及new.target这些值由外围最近一层非箭头函数决定。
    • 不能通过new关键字调用 箭头函数没有[[Construct]]方法,所以不能被用作构造函数
    • 没有原型  箭头函数不存在prototype这个属性
    • 不可以改变this绑定  函数内部this值不可以改变,箭头函数中的this值取决于该函数外部非箭头函数的值,并且不能通过bind(),apply(),call()方法改变this的值
    • 不支持arguments对象 箭头函数没有arguments绑定,所以必须通过命名参数和不定参数这两种形式访问函数的参数。
    • 不支持重复的命名参数

     

  • 相关阅读:
    WebView loadData乱码问题
    记录常用工具
    android toolbar学习
    百度地图V5.0地图定位
    JS调JAVA代码
    开始使用Android Stdio
    记录下平时看到的好句子
    开发者必备网址
    android:ellipsize实现跑马灯效果总结
    seo查询命令
  • 原文地址:https://www.cnblogs.com/smdb/p/10185886.html
Copyright © 2011-2022 走看看