Benefits of using `Object.create` for inheritance
I've been trying to wrap my head around the new Object.create method which was introduced in ECMAScript 5.Usually when I want to use inheritance I do something like this:var Animal = function(name) {...
View ArticleAnswer by user123444555621 for Benefits of using `Object.create` for inheritance
First, running the Animal constructor may have undesired side effects. Consider this:var Animal = function(name) { this.name = name; Animal.instances.push(this);};Animal.instances = [];This version...
View ArticleAnswer by Felix Kling for Benefits of using `Object.create` for inheritance
In the following I assume you are only interested in why Object.create is preferable for setting up inheritance.To understand the benefits, lets first clarify what a "class" is made of in JavaScript....
View ArticleAnswer by basilikum for Benefits of using `Object.create` for inheritance
I'm trying to illustrate the difference a little bit:Here is what basically happens when you write new Animal(): //creating a new object var res = {}; //setting the internal [[prototype]] property to...
View ArticleAnswer by Amit Kumar Gupta for Benefits of using `Object.create` for inheritance
Let's understand it with code only;A.prototype = B.prototype;function B() {console.log("I am B");this.b1= 30;} B.prototype.b2 = 40; function A() {console.log("I am A");this.a1= 10;} A.prototype.a2 =...
View Article