【发布时间】:2014-02-12 02:12:01
【问题描述】:
我正在尝试使用我使用 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;
我正在尝试在 index.html 中使用 foo。
输入命令后: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>
我在浏览器中做错了什么?提前致谢。
编辑: 错误示例。
原来的错误例子
foo.js:
var foo = {
f1: function(){
console.log('function1')
},
f2: function(){
console.log('function2')
}
};
module.exports = foo;
【问题讨论】:
标签: javascript jquery browserify