So, I am writing an application with the node/express + jade combo.(因此,我正在使用node / express + jade组合编写应用程序。)
I have client.js
, which is loaded on the client.(我有client.js
,它已加载到客户端上。) In that file I have code that calls functions from other JavaScript files.(在该文件中,我有调用其他JavaScript文件中的函数的代码。) My attempt was to use(我的尝试是使用)
var m = require('./messages');
in order to load the contents of messages.js
(just like I do on the server side) and later on call functions from that file.(为了加载messages.js
的内容(就像我在服务器端一样),然后再加载该文件的调用函数。) However, require
is not defined on the client side, and it throws an error of the form Uncaught ReferenceError: require is not defined
.(但是,在客户端未定义require
,并且抛出Uncaught ReferenceError: require is not defined
形式的错误Uncaught ReferenceError: require is not defined
。)
These other JS files are also loaded on runtime at the client because I place the links at the header of the webpage.(这些其他JS文件也会在运行时在客户端上加载,因为我将链接放置在网页的标题上。) So the client knows all the functions that are exported from these other files.(因此,客户端知道从这些其他文件导出的所有功能。)
How do I call these functions from these other JS files (such as messages.js
) in the main client.js
file that opens the socket to the server?(如何从打开服务器套接字的主client.js
文件中的其他其他JS文件(例如messages.js
)调用这些函数?)
ask by MightyMouse translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…