javascript - Passing a parameter to http.get in Node.JS -


i'm doing http or https request (depends on url) , want pass same callback function both http or https request.
problem want pass parameter callback function.
how can it?

for example how can pass myparameter callback function?

var myparameter = 1 if(url.indexof('https') === 0 ) {     https.get(url, callbackfunc); else{     http.get(url, callbackfunc); }  function callbackfunc(res, myparameter){} 

first, change parameter order of callbackfunc to

function callbackfunc(myparameter, res) {  } 

(myparameter first can bind shown below, res)

then can do:

var boundcallback = callbackfunc.bind(null, myparameter); 

then use boundcallback instead of callbackfunc when call http or https get.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -