Javascript inheritFrom Vs Prototype

I am wondering what is the difference between inheritFrom and prototype when defining inheritance in Javascript.

function classA{} classA.name="abc"; classA.functionName=function(){ alert("Function Name Alert"); } function classB{ } 

What is the difference in the codes below?

 classB.prototype=classA(); 

and

 classB.prototype.inheritFrom(classA); 
+4
source share
1 answer

B.prototype.inheritFrom(A) not standard JavaScript, while B.prototype = new A is standard JavaScript. I suggest exploring all aspects of JavaScript and embracing the prototype. You better know that. It really is not too complicated:

 function A(){} function B(){} B.prototype = new A; b = new B; console.log(b instanceof B, b instanceof A); //-> true, true 
+5
source

All Articles