这是什么文档语法意味着在MDN的JavaScript函数? [英] What does this documentation syntax mean at MDN for a JavaScript function?

查看:132
本文介绍了这是什么文档语法意味着在MDN的JavaScript函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过学习机锋的JavaScript手动JavaScript和现在,我从第5章<一做练习HREF =htt​​p://eloquentjavascript.net/05_higher_order.html相对=nofollow>高阶函数。其中一个本章介绍的功能是减少。我明白我的问题如何工作的,来了,当我试着去了解它在<定义href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Examples\"相对=nofollow> MDN 。我不明白语法定义它给了:

I'm learning JavaScript through "Eloquent JavaScript" manual and now I'm doing exercises from chapter 5 "High-Order Functions". One of the functions this chapter introduces you is "reduce". I understand how it works, my problem comes up when I try to understand its definition at MDN. I don't understand syntax definition it gives:

arr.reduce(callback[, initialValue])

本语法部分后跟部分称为参数。它们是:

This syntax sections is followed by the section called Parameters. These are:


  • 回调

    • previousValue

    • CurrentValue的

    • 首页

    • 阵列

    我不明白的是什么做的那些方括号和逗号是什么意思?因为当我看到方括号马上我认为在数组中。又为什么仅仅是初值的定义,而不是其他的参数?为什么会出现方括号之间没有空格回调

    What I don't understand is what do those square brackets and the comma mean? Because when I see square brackets immediately I think in arrays. And why is just initialValue in the definition and not the others parameters? Why there is no space between square brackets and callback?

    由于下面有两个例子:

    例1

    [0, 1, 2, 3, 4].reduce(function(previousValue, currentValue, index, array) {
        return previousValue + currentValue;
    });
    

    例2

    var total = [0, 1, 2, 3].reduce(function(a, b) {
        return a + b;
    });
    // total == 6
    

    和我不知道他们是如何适应的定义。

    and I don't know how do they fit into the definition.

    感谢

    推荐答案

    这通常是一个约定API单证使用 [] 来表示可选参数。但是, [] 不在使用的语法的一部分。这只是文档约定。

    It's usually a convention for API documentations to use [] to denote optional parameters. However, the [] is not part of the syntax on usage. It's just documentation convention.

    这篇关于这是什么文档语法意味着在MDN的JavaScript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆