Prototype inheritance. What is wrong with this simple example?

function a (){ this.testing = 'testing'; } function b (){ } b.prototype = new a(); console.log(b.testing); 

The console shows undefined, not "testing." What am I doing wrong?

+7
source share
1 answer

You have not made an instance of "b" yet.

 var bInstance = new b(); console.log(bInstance.testing); 

In other words, the properties of the prototype appear only on objects of type b , and not on the design function b() .

+10
source

All Articles