Let\'s say I have the following code snippet.
function test(id) { alert(id); }
testChild.prototype = new test();
function testChild(){}
var instance = new
You already have many answers, but I'll throw in the ES6 way, which IMHO is the new standard way to do this.
class Parent {
constructor() { alert('hi'); }
}
class Child extends Parent {
// Optionally include a constructor definition here. Leaving it
// out means the parent constructor is automatically invoked.
constructor() {
// imagine doing some custom stuff for this derived class
super(); // explicitly call parent constructor.
}
}
// Instantiate one:
var foo = new Child(); // alert: hi