您的位置:首页 > Web前端 > JavaScript

v8学习---添加带参数js全局函数

2013-11-10 10:24 309 查看
#include <v8.h>
using namespace v8;
void log(const v8::FunctionCallbackInfo<Value>& args)
{
String::AsciiValue ascii(args[0]);
printf("%s\n", *ascii);
}
int main()
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope handleScope(isolate);
Handle<ObjectTemplate> global = ObjectTemplate::New();
global->Set(String::New("log"), FunctionTemplate::New(log));
Handle<Context> context = Context::New(isolate, NULL, global);
Context::Scope context_scope(context);
Handle<Script> script = Script::Compile(String::New("log('good')"));
script->Run();
return 0;
}

留意log函数里参数的获取
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: