I'm wondering if there are any pros or cons when using the two approaches against each other:

我想知道在使用这两种方法时是否存在任何利弊:

first.js:

this.myFunction = function() {
    return 'herro first';
}

second.js:

module.exports = obj = {};
obj.myFunction = function() {
    return 'herro second';
}

The two above would then be included and used as so:

然后将上面两个包括在内并用作如下:

app.js:

var first = require('./first.js');
console.log(first.myFunction());

var second = require('./second');
console.log(second.myFunction());

1 个解决方案

#1


2

module.exports (or just exports) is the standard CommonJS way.

module.exports(或只是导出)是标准的CommonJS方式。

In Node.js, this happens to be the same object, but that is best not relied on, and using this will not work with other tools, for example Browserify

在Node.js中,这恰好是同一个对象,但最好不要依赖它,并且使用它不能与其他工具一起使用,例如Br​​owserify

更多相关文章

  1. Javascript学习:案例7--对象属性和方法的遍历、删除、添加.html
  2. Javascript正则表达式对象和美元符号
  3. 将JavaScript对象转换为要插入关系数据库的数组
  4. Javascript对象
  5. javascript数组和对象是否有设置顺序?
  6. JavaScript初探系列之面向对象
  7. 将对象值传递给指令而不是任何其他数据变量
  8. 对象的属性也要加引号吗
  9. 在javascript中过滤对象对象(过滤还是减少?)

随机推荐

  1. Android之列表对话框
  2. Android图片旋转实例
  3. Android中模拟点击软件的实现原理探究
  4. android微博客户端源代码
  5. Android中的android:layout_weight讲解
  6. android 相对布局
  7. Android获取当前时间
  8. Android ScrollView 去掉 scrollbar 和
  9. 日期和时间(DatePicker、TimePicker)
  10. Android中Json的解析和构建