Javascript function return number instead of object -
so, right now, have code looks this
var citibiz2 = new slao_stat(4, 25, 4, 55, splunktimecitibiz, "citibiz2", "citibiz", '0', 1, subcitibiz); var slao_stat = function(slahour, slamin, slohour, slomin, splunktime, statusname, mainarray, number, criticality, location) { this.slamin = slamin; this.slahour = slahour; this.slomin = slomin; this.slohour = slohour; //set sla , slo time each function var slatoday = new date(time.year, time.month, time.day, slahour, slamin); var slotoday = new date(time.year, time.month, time.day, slohour, slomin); //set sla , slo time next day var slatom = addday(slatoday, 1); var slotom = addday(slotoday, 1); //set sla time 12 hours before current var slayest = addday(slatoday, -.5); //set sla , slo time previous day var sloyes = addday(slotoday, -1); var slayes = addday(slatoday, -1); var slaout; var sloout; //if thing comes in between time came in last time , sla time tommorow, it's in. if (splunktime > slayest && splunktime < slatom) { slaout = slatom; sloout = slotom; } else { slaout = slatoday; sloout = slotoday; } //color conditionals if//(splunktime > slatoday || currenttime > midyes && splunktime < midyes && splunktime > slayest && currenttime < slotoday){ (currenttime > slatoday && splunktime > slatoday && splunktime != ""){ displaycolor = 4; main_gray++; //gray status graydiv = document.getelementbyid(location); document.getelementbyid(statusname).innerhtml = "<a href='#'><img src='gray.jpg' class = 'select' class = 'image-cropper'></a>"; if(criticality == 1) $('#gray_container' + number).prepend($(graydiv)); else $('#gray_container' + number).append($(graydiv)); }else if (currenttime < sloout) { //green; displaycolor = 1; main_green++; document.getelementbyid(statusname).innerhtml = "<a href='#'><img src='green.png' class = 'select' class = 'image-cropper'></a>"; } else if (currenttime > slaout) { //red displaycolor = 2; main_red++; //for main status document.getelementbyid(statusname).innerhtml = "<a href='#'><img src='red.png' class = 'select' class = 'image-cropper'></a>"; } else if (currenttime<slaout && currenttime>sloout) { //yellow displaycolor = 3; main_yellow++; //for main status document.getelementbyid(statusname).innerhtml = "<a href='#'><img src='yellow.png' class = 'select' class = 'image-cropper'></a>"; } else { //red displaycolor = 2; main_red++; //for main status document.getelementbyid(statusname).innerhtml = "<a href='#'><img src='red.png' class = 'select' class = 'image-cropper'></a>"; } if(mainarray == "citibiz"){ if(displaycolor == 4) cbrep = 4; else if(displaycolor == 2 && cbrep < 4)cbrep = 2; else if(displaycolor == 3 && cbrep < 2)cbrep = 3; else if(displaycolor == 1 && cbrep < 2)cbrep = 1; } else if(mainarray == "creditetl"){ if(displaycolor == 4) cetlrep = 4; else if(displaycolor == 2 && cetlrep < 4) cetlrep = 2; else if(displaycolor == 3 && cetlrep < 2) cetlrep = 3; else if(displaycolor == 1 && cetlrep < 2)cetlrep = 1; } else alert("there no array called " + mainarray); alert("dc " + displaycolor); return displaycolor; //returns [object object] instead of number };
my code series of things output number. return number instead of object. there way this?
again, simplified outline of happening in code. i'm asking if can done. thanks!
the issue you're calling function new
operator. constructing new object. depending on larger context you're working in, have 2 options.
option 1
don't create new object, , call function normal function:
var citibiz2 = slao_stat(4, 25...)
option 2
set displaycolor
property on object you're creating , use it. instead of:
return displaycolor;
you do:
this.displaycolor = displaycolor;
and access on object that's being created new
:
var citibiz2 = new slao_stat(4, 2...) alert(citibiz2.displaycolor); //should number
Comments
Post a Comment