I am learning about JS prototyping and inheritance, I had learned that the right way to do it is by:
function A(){}
A.prototype.doSomething=function(){}
function B(){}
B.prototype = new A();
console.log( (new B()) instanceof A);//true
console.log( (new B()) instanceof B);//true
As you can see I am setting new instance of A into B but as you can see it works great with
function A(){}
A.prototype.doSomething=function(){}
function B(){}
B.prototype = A.prototype;
console.log( (new B()) instanceof A);//true
console.log( (new B()) instanceof B);//true
but here: http://ejohn.org/apps/learn/#76
they claimed that prototype assignment is wrong,I don't understand why?
A.prototype.doSomething = function(){}?B.prototype = A.prototype;you will have((new B() instanceof A) == truebut also((new A()) instanceof B) == true, does as Grundy suggested. The site you posted fail in the instanceof test dueNinja.prototype = { dance: Person.prototype.dance };this break the prototype chain.