JavaScript Object constructor not showing stable value -


i have js code follows,

   function finddealerbyidresponse() { finddealerbyidresponse.prototype = finddealerbyidresponsetype;   this.getprefix = function(){         return "tns1"; }; this.getns = function(){     return "http://www.hp.com/bookservice"; };  }   function finddealerbyidresponsetype(){ var dealer ;   this.getprefix = function(){         return "tns1"; }; this.getns = function(){     return "http://www.hp.com/bookservice"; };   }  function getname( obj ) {      var funcnameregex = /function (.{1,})\(/;    var results = new object();    results = (funcnameregex).exec((obj).constructor.tostring());    return (results && results.length > 1) ? results[1] : ""; };  function test(){ var req = new finddealerbyidresponse(); alert(getname(req)); } 

but if perform "test" first time giving expected : "dotransactiontype" . afterwards giving "function" . please explain reason.

thanks

deepak

after first call finddealerbyidresponse, set prototype property function, namely finddealerbyidresponsetype. result, .constructor overwritten assignment, , resolve constructor of function - is, function, function.

instead, want this:

// set prototype parent instance finddealerbyidresponse.prototype = new finddealerbyidresponsetype;  // restore .constructor finddealerbyidresponse.prototype.constructor = finddealerbyidresponse; 

you'd want place after declarations of both functions.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -