1

Scenarios 1:

I have two file in my atom project weather.js and exmaple.js and weather is using export module to export everything to example.js and in turn example.js is using require module

my weather.js

var request = require('request');
module.exports= function(justAnothercallback) 
{
    justAnothercallback('This is from weather');
}

myExample.js

var fromWeather = require('./weather.js');
fromWeather(function(weather){
    console.log(weather); 
});

If I do Node myExample.js the output is : This is from weather

Scenarios 2: Now I just pass one more callback in my weather.js

module.exports= function(justAnothercallback, SecondCallback) {
    justAnothercallback('This is from weather');
    SecondCallback('This is second callback)');
}

And my example.js is modified to accommodate the second callback function !!

var fromWeather = require('./weather.js');
fromWeather(function(weather, anotherfunc){
    console.log(weather);
    console.log(anotherfunc);
});

From the terminal we get :

/>node example-callback.js This is from weather undefined /Users/NodeCourse/async/weather.js:7 SecondCallback('This is second callback)'); ^

TypeError: SecondCallback is not a function at module.exports (/Users/oogway/NodeCourse/async/weath

My question is are they not the same , I just added one more callback and it barfed !! why !!?? but it works fine if I pass just one callback .. Please help one this .

1 Answer 1

1

In your code here, you are only passing one callback with two parameters

var fromWeather = require('./weather.js');
  fromWeather(function(weather, anotherfunc){
    console.log(weather);
    console.log(anotherfunc);
  });

This is what two callbacks would look like

var fromWeather = require('./weather.js');
  fromWeather(function(){
    console.log('Hello from callback 1');
  }, function(){
    console.log('Hello from callback 2');
  });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.