In JavaScript inheritance how to differentiate Object.create vs new?

JavascriptObject Oriented ProgrammingFront End Technology

In the first example, you are just inheriting amitBaseClass prototype.

function SomeClass() {
}

SomeClass.prototype = Object.create(amitBaseClass.prototype);

In the second example, you are executing the constructor function. An instance of amitBaseClass is created and you are inheriting the who complete amitBaseClass object.

function SomeClass () {
}

SomeClass.prototype = new amitBaseClass ();

So, both are doing separate work.

raja
Published on 01-Mar-2018 06:52:53
Advertisements