I try to do elementary inheritance

function hot () { this.time = 44; this.has = true } function hot2 () { this.desc = 'some'; } hot2.prototype = hot(); var f = new hot2(); console.log(f.has); 

writes undefined why I cannot access the hot function variables through the hot2 instance

    2 answers 2

    Here you set the prototype to null, since a simple call to the hot function does not return anything:

     hot2.prototype = hot(); 

    To make the prototype an object with the fields you need, create an instance:

     hot2.prototype = new hot(); 

    or return this (this option is better not to use):

     function hot () { this.time = 44; this.has = true; return this; } 

      In general, read about inheritance . It's kind of weird here. Your hot function does not return anything, but you also stuff it into prototype after calling it. So it will be better:

       function hot () { return { time: 44, has: true } } function hot2 () { this.desc = 'some'; } hot2.prototype = hot(); var f = new hot2(); console.log(f.has);