This is my code -
function searchString(usrLogin) {
var setUsrLogin = function (usrLogin) {
this.usrLogin = (usrLogin == "") ? "*" : usrLogin;
}
this.toString = function(){
return 'source="dbmon-dump://Source/ID" ' + 'USR_LOGIN="' + this.usrLogin + '" ';
}
setUsrLogin(usrLogin);
}
$(function() {
var a = new searchString("");
$('#searchBar').val(a.toString());
});
a.toString() prints source="dbmon-dump://Source/ID" USR_LOGIN="undefined" because this.usrLogin shows up as undefined. What am I doing wrong?
thisin the same functions are the same thing. Did you learn that somewhere? They're entirely separate. There are different solutions, but I'm not sure why you have these nested function in the first place.var setUsrLogin = func...tothis.setUsrLogin = func..., then change the invocation tothis.setUsrLogin(usrLogin). But overall there seems to be more functions here than needed.