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

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

问题描述

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

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

this._render();

它在别处被定义为:

_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天全站免登陆