How to deal with a.js quoting b.js

8 views
Skip to first unread message

chunmi...@gmail.com

unread,
May 23, 2013, 5:49:44 AM5/23/13
to v8-u...@googlegroups.com
Hi, Everyone, 
I do a test, a.js call function 'b()' in b.js.
a.js is the main work file, 
b.js is the library of functions developed by another develoer.

In Chrome, I can using the following code, the test goes well.
//----------------------------------------------------------
a.js:
new_element=document.createElement("script"); 
new_element.setAttribute("type", "text/javascript"); 
new_element.setAttribute("src", "b.js"); 
document.body.appendChild(new_element); 
function a()
{
   //...
   b();
}

b.js:
function b()
{
   //...
}
//----------------------------------------------------------

Now, I need do the test with V8, I can use the following code, but it will be complicated and not elegant 
//----------------------------------------------------------
string scriptFileText = getFileContents("a.js") + getFileContents("b.js");
Handle<String> scriptSource = String::New(scriptFileText.c_str());
Handle<Script> script = Script::Compile(scriptSource);

How can I deal with it, Any of your help will be appreciated! 
Reply all
Reply to author
Forward
0 new messages