#) or closures.
Class Syntax (ES6+)
In modern JavaScript classes, methods defined without the# prefix are implicitly public. They are attached to the class’s prototype rather than the individual instance, optimizing memory allocation.
Constructor Functions and Prototypes (Pre-ES6)
Before the introduction of theclass keyword, public methods were defined either by attaching them directly to the instance context (this) or by mutating the constructor’s prototype object.
Object Literals
Methods defined within object literals are inherently public properties of that specific object.Technical Characteristics
- Invocation and Context: Public methods are invoked using property accessors (dot
.or bracket[]notation). During invocation, the execution context (this) is dynamically bound to the object preceding the dot, unless the method is an arrow function (which retains its lexicalthis) or the context is explicitly overridden using.bind(),.call(), or.apply(). - Enumerability:
- Public methods defined via ES6
classsyntax are non-enumerable by default. They will not appear infor...inloops orObject.keys(). - Public methods attached directly to
thisin a constructor or defined in an object literal are enumerable by default.
- Public methods defined via ES6
- Mutability: Unless the object or its prototype is explicitly frozen (
Object.freeze()), public methods can be overwritten, deleted, or monkey-patched at runtime by external scripts.
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More





