一个node.js如何检查参数types

我使用node.js一段时间,现在我需要编写一个附加组件,但是我是c ++的新手。

在node.js中,我可以传递可选参数到函数,并检查它们的types。

function hello(arg, options, callback){ if(!callback){ if(typeof options === 'function'){ callback = options; options = {}; } } console.log(typeof arg); } 

但在一个插件。

 Handle<Value> hello(const Arguments &args) { HandleScope scope; printf("%d\n", args.Length()); // how to check type of args[i] return String::New("world"); } 

您应该查看http://v8.googlecode.com/svn/trunk/include/v8.h中的API&#x3002; 你感兴趣的大部分function都在Value类上。 网上有文档, http://bespin.cz/~ondras/html/classv8_1_1Value.html,但是看起来就像是一些随机的人上传的文档版本&#x3002; 不知道他们是否在其他地方在线。

像这样的东西应该做你的JS片段相同的事情。

 Handle<Value> hello(const Arguments &args) { HandleScope scope; Local<Value> arg(args[0]); Local<Value> options(args[1]); Local<Value> callback(args[2]); if (callback.equals(False())) { if (options->IsFunction()) { callback = options; options = Object::New(); } } // ... }