Quantcast
Channel: Benefits of using `Object.create` for inheritance - Stack Overflow
Browsing index pages (5 articles)

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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Image may be NSFW.
Clik here to view.

Answer 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

Browsing index pages (5 articles)


Latest Images