我正在尝试使用我从使用 browserify 的 javascript 文件中公开的对象,但我不断收到错误消息Uncaught TypeError: undefined is not a function
这是一个例子:
foo.js:
var foo = function() {
  this.f1 = function(){
    console.log('function1')
  }
  this.f2 = function(){
    console.log('function2')
  }
};
module.exports = foo;
我正在尝试foo在 index.html 中使用。
输入命令后:browserify foo.js > bundle.js
并包含bundle.js到 html 文件中。
index.html:
<html>
  <head>
    <script src="./bundle.js"></script>
    <script>
      var foo = new foo();  // Uncaught TypeError: undefined is not a function
      foo.f1();
    </script>
  </head>
  <body>
  </body>
</html>
我在 browserify 上做错了什么?提前致谢。
编辑:错误的例子。
原始错误示例
foo.js:
var foo = {
  f1: function(){
    console.log('function1')
  },
  f2: function(){
    console.log('function2')
  }
};
module.exports = foo;