didiercrunch
didiercrunch16mo ago

What a method prefixed with `#` means?

This is perhaps the stupidest question ever. But I often see method with names prefixed with a # character in typescript. What does it mean? Google does not seems to know either. example: https://deno.land/std@0.187.0/streams/text_line_stream.ts?source#L40
4 Replies
Andreu Botella (they/them)
It's a private method
crowlKats
crowlKats16mo ago
Private class features - JavaScript | MDN
Class fields are public by default, but private class members can be created by using a hash # prefix. The privacy encapsulation of these class features is enforced by JavaScript itself.
didiercrunch
didiercrunch16mo ago
nice, thanks a lot. I was using the private keyword.
AapoAlas
AapoAlas16mo ago
private is TypeScript-level private only, ie. in runtime the property or method is still entirely public and visible there. # is runtime-private as well, and it is actually one of the strongest possible flavours of privateness, eg. private class fields cannot be accessed by sub-classes. In short: There's a time and place for both.