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
Post a Comment