I am trying to inherit the members from test1 into test2 but it does not work.
function inherit(a, b)
{
// none of these work
//a.prototype = b;
//a.prototype = b();
//a.prototype = new b();
//a.prototype = Object.create(b.prototype);
//a.prototype = Object.create(b);
//a.prototype = b.prototype;
}
function test1()
{
this.val1 = 123;
}
function test2()
{
this.val2 = 456;
}
var testInstance = new test2();
inherit(testInstance, test1);
console.log(testInstance.val1);
How can I make test2 inherit the members of test1?