简体   繁体   中英

What is the purpose of a parameter, with an underscore before it, that is not used inside the function?

I am reading an article about how somebody went about building a data table with React - https://engineering.shopify.com/blogs/engineering/building-data-table-component-react . The following method is on the DataTable component. What is the purpose of the _cell parameter? It is not used inside the method!

renderHeadingRow = (_cell, cellIndex) => {
    const { headings } = this.props;

    return (
        <Cell
            key={`heading-${cellIndex}`}
            content={headings[cellIndex]}
            header={true}
        />
    )
}

The underscore is used in order the IDEs don't warn you about an unused parameter. So, if you need to access the second parameter of the function but you won't use the first one, you can add an underscore to prevent the warning of unused parameter.

这只是表明参数从未在函数作用域内使用过的标准,但您需要使用它来访问第二个参数。

_ Naming conventions are rarely used, and when used it is used to denote PRIVATE . Even though it cannot be really enforced by JavaScript, declaring something as private tells us about how it should be used or how it should not be used.

For instance, a private method in a class should only be used internally by the class, but should be avoided to be used on the instance of the class.

Read More Here : https://www.robinwieruch.de/javascript-naming-conventions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM