var io = require('../..')(server)的作用是什么? [英] what does var io = require('../..')(server) do?
问题描述
我已经构建了项目 https://github.com/Automattic/socket.io/tree/master/examples/chat 在本地运行,效果很好.但是,最好能多了解一些套接字应用程序的工作原理.
I've build the project https://github.com/Automattic/socket.io/tree/master/examples/chat locally and it is working great. However, it would be nice to understand a little more about how a socket application works.
在主启动脚本中,需要插入的模块之一是
In the main startup script one of the modules that is pulled in with require is
var io = require('../..')(server)
require('../..')需要做什么?
what does require('../..') do?
谢谢!
推荐答案
将目录路径提供给require
时,它将隐式在该目录中查找index.js
.
When a path to a directory is given to require
, it will implicitly look for an index.js
in that directory.
在这种情况下,等同于
var socket = require("../../index.js");
var io = socket(server);
在提供的示例中,他们只是使用一些速记并丢弃了对require
的调用返回的中间值.
In the example provided, they're just using some shorthand and throw away the intermediate value returned by the call to require
.
查看 module.require文档以获得更多信息.
这篇关于var io = require('../..')(server)的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!