how to call parent constructor?

后端 未结 5 478
感动是毒
感动是毒 2020-12-23 17:20

Let\'s say I have the following code snippet.

function test(id) { alert(id); }

testChild.prototype = new test();

function testChild(){}

var instance = new         


        
5条回答
  •  天命终不由人
    2020-12-23 17:38

    You need to declare the function testChild() before you set its prototype. Then you need to call testChild.test to call the method. I believe you want to set testChild.prototype.test = test, then you can call testChild.test('hi') and it should resolve properly.

提交回复
热议问题