require()实际上返回的是文件还是函数
What does require() actually return, the file or the function
例如,我有profile.js
var EventEmitter = require("events").EventEmitter;
var https = require("https");
var http = require("http");
var util = require("util");
function Profile(username) {
// function code here
}
util.inherits( Profile, EventEmitter );
module.exports = Profile;
在app.js中,我有
var Profile = require("./profile.js");
var studentProfile = new Profile("chalkers");
/**
* When the JSON body is fully recieved the
* the "end" event is triggered and the full body
* is given to the handler or callback
**/
studentProfile.on("end", console.dir);
/**
* If a parsing, network or HTTP error occurs an
* error object is passed in to the handler or callback
**/
studentProfile.on("error", console.error);
所以变量是Profile .js本身还是函数Profile(用户名)?如果profile.js有不同的函数,假设我在profile.js中有SetProfile(username)函数,我该如何导出这两个函数并在app.js中使用它们?
require(...)
函数从"required"模块返回module.exports
值,在这种情况下是Profile
函数。
顺便说一句,我不知道"返回文件"或" Profile是Profile .js本身"是什么意思。
相关文章:
- 通过Ajax将JavaScript函数传递给PHP文件
- 在不破坏未定义函数的情况下,对多个视图使用单个js文件
- 如何在 javascript 文件函数中找到 Radnotification id
- 对另一个文件函数的引用
- 从代码隐藏调用.js文件函数
- 如何javascript调用iframe加载的文件函数
- Javascript外部文件函数赢得'我以前不工作
- 读取本地文本文件函数不返回字符串类型,而是返回一个void类型
- 如何使用javascript在同一位置编辑和保存计算机中的任何文本文件.函数调用时,
- 如何用javascript调用jar文件函数
- 从SharePoint 2013脚本编辑器调用外部javascript文件函数
- 优先使用JS文件函数而不是HTML文件
- 如何从页面后面的代码调用js文件函数
- 外部JS文件's函数在无限滚动后不加载
- 在HTML按钮点击事件上调用jquery文件函数
- 在Angular js控制器中调用外部js文件函数
- Webpack主javascript文件's函数不能在加载在页脚的js文件中访问
- 我的jquery文档准备函数不能识别外部js文件函数
- 调用selenium-ide中的js文件函数
- 在RegisterStartupScript方法中使用外部Javascript文件函数