How to create public and private members?

前端 未结 6 1814
小鲜肉
小鲜肉 2020-12-17 03:22

I\'m a bit confused, how can I create public and private members.

My code template so far is like:

(function()){
   var _blah = 1;

   someFunction =         


        
6条回答
  •  隐瞒了意图╮
    2020-12-17 03:33

    You don't. You can rely on convention, prepending _ to your private attributes, and then not touching them with code that shouldn't be using it.

    Or you can use the function scope to create variables that can't be accessed from outside.

提交回复
热议问题