javascript - Use a function with parameters inside a callback -


i've written function may take unknown number of functions parameters, can't figure how can make work when 1 or more of functions take parameters too.

here quick example of achieve:

function talk(name) {   console.log('my name ' + name);   var callbacks = [].slice.call(arguments, 1);   callbacks.foreach(function(callback) {     callback();   }); }  function hello() {   console.log('hello guys'); }  function weather(meteo) {   console.log('the weather ' + meteo); }  function goodbye() {   console.log('goodbye'); }  // able following: //talk('john', hello, weather('sunny'), goodbye); 

you can pass anonymous function can call function required parameters

talk('john', hello, function(){     weather('sunny') }, goodbye); 

function talk(name) {    console.log('my name ' + name);    var callbacks = [].slice.call(arguments, 1);    callbacks.foreach(function(callback) {      callback();    });  }    function hello() {    console.log('hello guys');  }    function weather(meteo) {    console.log('the weather ' + meteo);  }    function goodbye() {    console.log('goodbye');  }    talk('john', hello, function() {    weather('sunny')  }, goodbye);


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -