我是node.js的新手,而且我无法理解我所看到的一些事情。变量“||”是什么意思运算符用于以下情况?
var server = function(config) {
config = config || {};
var server_root = config.server_root || '';
// ...
}
另外,我来自C#,其中所有类型和东西都被整齐地命名和定义,所以我很好奇调用函数如何知道配置的类型是什么。在我看的示例代码中,它被称为:
// I guess this is adding a new start function to the server "class"
server.start = function(config) {
var instance = new server(config);
instance.start();
return instance;
};
// and here is where the start function is called. But how do I know what the type of the config is???
server.start({
port:8080,
preRequest: function(json,req,res) { ... },
postRequest: function(json,req,res) { ... }
});