ES6之函数的扩展
发布日期:2021-05-10 22:11:14 浏览次数:10 分类:精选文章

本文共 3756 字,大约阅读时间需要 12 分钟。

ES6 ������������������

ES6 ���������������������������������������������������������������������������������������������������������������������������������������

������������������������

���������������������������������������������������������������������������������������������������������

������

function fn(x = 10, y = 20) {
console.log(x, y);
}
fn(); // 10 20

������������

  • ��������������������������������������������� let ��� const ���������������
  • ������������������������������������ undefined��������������������� null ���������������
  • ������������������������������������������������������������������������
  • ���������������������������������������

    function fn({x = 10, y = 20} = {}) {
    console.log(x, y);
    }
    fn(); // 10 20
    fn({x: 30, y: 40}); // 30 40

    ��������������� Length ������

    Length ���������������������������������������������������������������������Length ���������������������������������������������������������������������

    ������

    function fn(a, b, c) {
    }
    console.log(fn.length); // 3
    function fn(a = 0, b, c) {
    }
    console.log(fn.length); // 0
    function fn(a, b = 0, c) {
    }
    console.log(fn.length); // 1
    function fn(a, b, c = 0) {
    }
    console.log(fn.length); // 2
    function fn(a = 0, b = 0, c) {
    }
    console.log(fn.length); // 0

    ������������������������

    ������������������������������������������������������������������������������������������������������������������������������������������������������

    ������ 1

    var a = 1;
    function fn(a, b = a) {
    console.log(a); // 10
    }
    fn(10); // ������ a ��� b ������

    ������ 2

    var a = 1;
    function fn(b = a) {
    var a = 10;
    console.log(b); // ��������� a = 1
    }
    fn(); // ������ 1

    Rest ������������������������

    Rest ��������������������������������������������������������������� arguments ���������

    ������

    function fn(...val) {
    console.log(val);
    }
    fn(1, 2, 3); // [1, 2, 3]

    ������������

    ��� ES6 ������������������������������������������ Rest ������������������������������������������������

    ������

    function fn() {
    'use strict';
    }

    ���������������

    ES6 ������������ name ��������������������������������������������������������������������������������� "anonymous"������������������������ bind ������ this ������������ name���

    ������

    function fn() {
    }
    console.log(fn.name); // fn
    var fn = function () {
    };
    console.log(fn.name); // fn
    var fn = function ffn () {
    };
    console.log(fn.name); // ffn
    console.log((new Function()).name); // anonymous
    var fn = function () {
    };
    fn = fn.bind({}); // bound fn
    console.log(fn.name); // bound fn

    ������������

    ���������������������������������������������������������������������������������

    ������

    const fn = () => {
    return "Hello World";
    };

    ���������������������XSMB���

    ���������������������??��������������������������������������������������� Object.prototype ������������������

    ������

    const fn = await (() => {
    // ...
    }).call(context);

    ���������������

    ��� strict ��������������������������������������������������������������������� respondent���

    ������

    function fn(n) {
    if (n === 0) {
    return;
    }
    fn(n - 1);
    }
    console.log(fn(5)); // 5 4 3 2 1 0 (���������������������������������������������)

    ������ 2

    function fn(n) {
    return fib(n);
    }
    function fib(n) {
    return fib(n - 1) + fib(n - 2);
    }
    // ��������������������������� fib ���������������

    ������������������������

    ES7 ���������������������������������������������������������������������������������

    ������

    function fn(a, b,) {
    console.log(a, b);
    }
    fn(10, 20,);

    Coding ������������

    ������������������������������������ ES6 ���������������������Rest ������������������������������������������������������������������������������������ JavaScript ���������������������������������������������������������������������������������������������������������������

    上一篇:ES6之Set和Map数据结构
    下一篇:ES6之symbol

    发表评论

    最新留言

    网站不错 人气很旺了 加油
    [***.192.178.218]2025年04月18日 20时24分36秒