你如何在node.js中调用这个函数? [英] How do you call this function in node.js ?
本文介绍了你如何在node.js中调用这个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想弄清楚如何在node.js中调用函数square。问题是square函数本身需要2个参数,一个是宽度,第二个是另一个让我困惑的函数数据,因为我不知道如何调用另一个函数作为参数。
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.
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);
我尝试了什么:
来自 js-use-of-module-exports-as-a-constructor> javascript - Node.js - 使用module.exports作为构造函数 - Stack Overflow [ ^ ]
推荐答案
你必须这样称呼它
Hi,
you have to call it like this
var s = new square(5, function(result){
console.log(result);
});
干杯
Alessio
Cheers
Alessio
这篇关于你如何在node.js中调用这个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文