1
初始化我有這樣的(這是一個Node.js的插件)給整數默認值,如果它們是作爲空
void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
int count = args[2]->ToNumber()->NumberValue();
int priority = args[3]->ToNumber()->NumberValue();
int priority_search_cap = args[4]->ToNumber()->NumberValue();
cout << " count => " << count << endl;
cout << " priority => " << priority << endl;
cout << " priority_search_cap => " << priority_search_cap << endl;
}
我所得到的註銷是:
count => -2147483648
priority => -2147483648
priority_search_cap => -2147483648
我想什麼要做的是給這些變量的默認值,以防沒有值傳遞給他們正確地初始化它們? (含義,args [2],args [3],args [4]未定義。)
如何給這些整數默認值?
爲什麼不在調用'ToNumber'之前檢查args類型(例如'Value :: IsUndefined')? – DMaster