9 topics · 0/9 read
JavaScript Part 4 (OOP)
Object-Oriented Programming concepts including Factory Functions, Constructors, Classes, Prototypes, and Inheritance
Factory Functions
A factory function is a function that returns a new object. It is a simple way to create multiple objects with shared properties and methods without using classes or constructors.
Read nowConstructor Functions
A constructor function is a function used to create objects and is invoked with the `new` keyword. It automates object creation and initializes properties.
Read nowES6 Class Constructors
ES6 introduces the `class` keyword as syntactic sugar over constructor functions. It provides a cleaner and more readable way to create objects and handle inheritance.
Read nowprototype
The `prototype` is an object associated with every function and object in JavaScript. It is used to share methods and properties among instances of an object, reducing memory usage.
Read nowObject.create()
The `Object.create()` method creates a new object with the specified prototype and properties.
Read nowsetPrototypeOf() and getPrototypeOf()
`Object.setPrototypeOf()` sets the prototype of an object, while `Object.getPrototypeOf()` retrieves the prototype of an object.
Read nowconstructor.prototype.key = value
Adding methods or properties to a constructor function's prototype makes them accessible to all instances created by that constructor.
Read nowES6 Class Methods and Prototypes
Methods written in ES6 class syntax are automatically added to the `prototype` of the class, ensuring shared access among instances.
Read now__proto__
`__proto__` is an internal property available on all objects in JavaScript. It is a reference to the prototype of the object. It provides access to the prototype chain, which is the mechanism JavaScript uses to inherit p
Read now