# Private properties for function

**URL:** <https://es.discourse.group/t/private-properties-for-function/2034>\
**Category:** 💡 Ideas\
**Created:** [May 12, 2024, 3:19pm UTC](https://es.discourse.group/t/private-properties-for-function/2034 "2024-05-12T15:19:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonkcleung](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/simonkcleung/32/785_2.png) [@simonkcleung](https://es.discourse.group/u/simonkcleung)\
**Post date:** [May 12, 2024, 3:19pm UTC](https://es.discourse.group/t/private-properties-for-function/2034/1 "2024-05-12T15:19:37Z")

</div>

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

```javascript
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

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

```

It could be improved in this way:

```javascript
          #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.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [May 12, 2024, 8:18pm UTC](https://es.discourse.group/t/private-properties-for-function/2034/2 "2024-05-12T20:18:44Z")

</div>

Similar threads:

- [C-style static variables](https://es.discourse.group/t/c-style-static-variables/511)

- [Proposal: Function static variables and blocks](https://es.discourse.group/t/proposal-function-static-variables-and-blocks/1781)
