什么是下划线“_”在JavaScript? [英] What is the underscore "_" in JavaScript?

查看:75
本文介绍了什么是下划线“_”在JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个redux教程,我看到这样的调用:

I'm doing a redux tutorial, and I saw a call like this:

this._render();

并且在其他地方定义为:

and it's defined elsewhere as:

_render() {
    ....
} 

什么是下划线_?为什么使用?

What is the underscore "_"? Why is it used?

推荐答案

这是私有方法和变量的约定。在JavaScript中,没有真正的类隐私。

This is convention of private methods and variables. In JavaScript there is no real privacy of classes.

这意味着你不应该使用这些方法(以 _ 开头)。当然技术上你可以,但 _ 意味着你不应该。

It means that you should not use these method (starting with "_") out of your object. Of course technically you can, but "_" means that you should not.

这篇关于什么是下划线“_”在JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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