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.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -