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;