Why do we use _ in variable names?

前端 未结 11 1879
一生所求
一生所求 2020-12-25 11:26

I have seen variables like _ image and was wondering what _ meant?

11条回答
  •  感情败类
    2020-12-25 12:07

    In most languages, it doesn't actually affect the functionality of the code, but is often used to denote reserved or internal names.

    It is common in some languages to name your instance variable _image or image_ and then make the public method used to access it image().

    Similarly, some names like __FILE__ are used in some languages to denote a special variable or constant created by the interpreter or compiler; such names are often reserved to encourage programmers to avoid using those names in their own programs in case the names are used in future versions of the language.

提交回复
热议问题