gpt4 book ai didi

javascript - 我的 Browserify JavaScript 代码有什么问题?

转载 作者:行者123 更新时间:2023-12-03 10:35:36 27 4
gpt4 key购买 nike

在我的 main.js 中,我有:

var example = require('./test');
example.speak('Hello world');

在我的 test.js 中,我有:

module.exports = function() {
this.speak = function(str) {
str += ' < you typed.';
return str;
};
this.listen = function(str) {
return str;
};
};

我到底做错了什么,才能正确使用 browserify

最佳答案

您应该导出一个对象:

module.exports = {
speak: function () {},
// etc
}

或使用

var example = new require("./test")();

关于javascript - 我的 Browserify JavaScript 代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28998318/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com