javascript - Get child function name in parent function method -
function b extends a, how b function name in parent function a, when call parentmethod()
on object of b child function object.
function a() { this.parentmethod = function() { //alert('display b function name'); } } function b() { } b.prototype = new a(); var b = new b(); b.parentmethod();
simplest way is:
function a() { this.parentmethod = function() { alert(this.constructor.name); } } function b() { } b.prototype = new a(); b.prototype.constructor = b; //add line. var b = new b(); b.parentmethod();
now when call parentmethod display b constructor name.