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

Php - Delimiter must not be alphanumeric or backslash -

c# - How to change the "Applies To" field under folder auditing options programatically (.NET) -

c++ - Ambiguity when using boost::assign::list_of to construct a std::vector -