javascript - Calling function inside another function - uncaught error -


i don't know if 'parameter' right term, i'm trying call function inside function , i'm getting following error:

uncaught referenceerror: successmsg not defined 

i'm looping through trello board through api looks this

var sportsuccess = function(successmsg) {   console.log("sport");     looptrellocards(); };  trello.get('/lists/boardid/cards', sportsuccess, error); 

and looptrellocards function looks like

function looptrellocards() {   for(i = 0; < successmsg.length; i++) {     var name = successmsg[i].name;     var desc = successmsg[i].desc;     var due = successmsg[i].due;     var date = new date(due);     var day = addzerotodate(date.getdate());     var month = addzerotodate(date.getmonth() + 1);     var year = string(date.getfullyear());     var eventdateshort = year + month + day;     if (today < eventdateshort) {       var year = year.substr(2);       var eventdate = day + '.' + month + '.' + year;       console.log(name + '  ' + desc + '  ' + eventdate);     }   } } 

when place code inside function inside sportssuccess function works, when call looptrellocards inside sportssuccess breaks.

also, can let me know if term used (parameter) right? call this?

parameters in javascript local variables function' scope. so, not passing successmsg parameter, not accessible inner function.

your options are:

  • pass successmsg parameter inner function.
  • define successmsg global variable (outside functions) , access there.
  • not use inner function , put logic in main function.

quoting w3schools:

function arguments function arguments (parameters) work local variables inside functions. 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -