Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I 'm trying to figure out how to call the function square in node.js. Problem is that the square function itself expects 2 parameters , one the width and second one is another function data which is confusing to me , as i dont know how to call the a function which has another function as paramter.



JavaScript
square(width,function (data)
{
   console.log(data.squareVal);
});


exports.square = function(width,callback)
{
     var aa = new Object();
     callback(aa.squareVal = width * width);    
}


var s = new square(5);

console.log(s);


What I have tried:

from javascript - Node.js - use of module.exports as a constructor - Stack Overflow[^]
Posted
Updated 17-Jan-17 5:20am

1 solution

Hi,
you have to call it like this

JavaScript
var s = new square(5, function(result){
  console.log(result);
});


Cheers
Alessio
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900