-
JavaScript Prototype Methods, Objects Without __proto__
Let’s first explore the modern methods for setting up a prototype. Amongst them are: So, you can use the mentioned methods instead of the __proto__. Take a look at the following example: There is an alternative argument for Object.create: property descriptors. You have the option of providing additional properties to the object there. For example: For performing…
-
JavaScript Native Prototypes
The “prototype” property is commonly used by the core of JavaScript. It is used by all the built-in constructor functions. Let’s start at the details. Object.prototype Imagine you output an object that is empty: Probably, you wonder where the code creating the string “[object Object]” is. It is the built-in toString method. But, in fact, the obj is empty. Note that short notation obj…
-
JavaScript F.prototype
JavaScript allows creating objects using a constructor function, like the new F(). Once F.prototype is an object, the new operator may use it for setting [[Prototype]] for the new object. Please, take into consideration that here F.prototype means an ordinary property, known as “prototype” on F. It may sound similar to the term “prototype.” Still, here it is intended an ordinary property with this name. For instance:…
-
JavaScript Prototypal inheritance
In programming, it is often necessary to take something and extend it. For example, there is a user object with its methods and properties. You intend to make admin and guest as pretty modified variants of it. So you wish to reuse what you have in the user, building a new object on top of it. The prototypal inheritance feature is there…