Private properties for function

Similar to private properties in Class but in a function that uses a # to declare a variable. e.g.

function print(){
  #something = getsomething(); // as if print.#something= getsomething()
  console.log(something);   // as if  console.log(print.#something);    
}

When print() is called 2nd time, #something = getsomething(); is ignored.

Use case:
In event.js library of node.js, I find that

......
          if (spliceOne === undefined)
            spliceOne = require('internal/util').spliceOne;
          spliceOne(list, position);
......

It could be improved in this way:

          #spliceOne = require('internal/util').spliceOne;
          spliceOne(list, position);

The benefits is no need to declare a variable in top level and no more checking of its existence needed.

Similar threads:

2 Likes