我的一位同事建议我在文件顶部声明变量
var a,b,c,d;
// or
var a=1,b=1,c=1,d=1;
Run Code Online (Sandbox Code Playgroud)
代替
var a=1;
//some code
var b =1;
//some code
var c=1;
//some code
var d=1;
Run Code Online (Sandbox Code Playgroud)
说这会影响JS的表现.
这真的有什么不同吗?
请抱歉,我是JavaScript和TypeScript专家,不是c ++专家。
但是JS引擎V8是用c ++编写的,这是那里的代码:
// Convert the result to an UTF8 string and print it.
v8::String::Utf8Value utf8(isolate, result);
printf("%s\n", *utf8);
Run Code Online (Sandbox Code Playgroud)
在上面的代码中有两行。第一行包含utf8功能...它来自哪里?我之前在文件中没有看到它,也没有导入它(还是它)?
第二行包含utf8变量(对吗?),但带有*我不知道的修饰符。变量来自哪里?星形修饰剂的作用是什么?
很抱歉遇到这样的问题,但是在这一点上,我无法深入研究最复杂的语言之一的文档,即c ++。
根据我的理解,typedef语法是:
typedef existing_type new_type_name;
Run Code Online (Sandbox Code Playgroud)
但是,在Chrome的v8命名空间中,有许多typedef似乎与其他语法一起使用.例如,
typedef void(* FunctionCallback )(const FunctionCallbackInfo< Value > &info)
Run Code Online (Sandbox Code Playgroud)
有两点我不明白:
1- FunctionCallbackInfo <Value>是在命名空间中定义的类,而FunctionCallback不是; 应该是先存在的现有类型?
2-没有空格分隔existing_type和new_type_name
读取它的正确方法是什么?
编辑:我正在学习本教程中的所有typedef信息.
我总是想知道为什么我不能在Node.js终端上使用C++语法.
例如,V8是一个实现ECMAScript的JavaScript引擎.Node.js本身是一个C++程序,它告诉V8引擎使用它的功能.所以这些函数是用C++代码编写的,因此这个应用程序应该能够采用C++本机语法.这意味着如果我要在Node.js终端中键入C++代码,那么Node.js终端应该能够将这些语法传递给Node.js核心中的C++模块并成功输出.但相反,它给出了:
SyntaxError: Unexpected identifier
at Object.exports.createScript (vm.js:24:10)
at REPLServer.defaultEval (repl.js:236:25)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:441:10)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:188:7)
at REPLServer.Interface._onLine (readline.js:224:10)
at REPLServer.Interface._line (readline.js:566:8)
at REPLServer.Interface._ttyWrite (readline.js:843:14)
Run Code Online (Sandbox Code Playgroud)
我只是在寻找一个清晰的解释,虽然Node.js是在C++之上编写的,但是这两种语言是如何被抽象的.