0

I'm used to seeing hashes in older Angular (< 10) versions in the HTML templates to declare DOM elements as variables.

But in Angular 10 I found examples where hashes are used inside component classes.

class Product {

  #name: string;

  get name(): string {
    return this.#name;
  }
}

Can anyone explain to me how it works?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
zerocewl
  • 11,401
  • 6
  • 27
  • 53
  • where is that example ? provide the relevant link ? – micronyks Jul 26 '20 at 15:44
  • It's not part of Angular, see https://github.com/tc39/proposal-private-methods – jonrsharpe Jul 26 '20 at 15:47
  • 1
    Does this answer your question? [Private properties in JavaScript ES6 classes](https://stackoverflow.com/questions/22156326/private-properties-in-javascript-es6-classes) – jonrsharpe Jul 26 '20 at 15:48
  • See also e.g. https://stackoverflow.com/questions/59641564/what-are-the-differences-between-the-private-keyword-and-private-fields-in-types – jonrsharpe Jul 26 '20 at 15:51

1 Answers1

0

It's a way to mark fields as private. This function is experimental. Some browsers does not support it.

JoH
  • 514
  • 1
  • 6
  • 16