在 node.js 和 nw.js 中导出模块但无法调用构造函数
exporting module in node.js and nw.js but unable to call to constructor
我正在使用 node.js 和 nw.js 创建 Web 应用程序
现在我正在导出以下模块
admin.js
module.exports = function (firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.fullName = function () {
return this.firstName + ' ' + this.lastName;
}}
and trying to access it in login.js file
var adm= require('./model/admin.js');
var adms=new adm("hi","wow");
adms.fullName();
But it says adm is not a constructor
你的代码看起来很棒。
也许可以尝试更改您的 admin.js,但通常您的代码应该可以工作
var adm = function (firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.fullName = function () {
return this.firstName + ' ' + this.lastName;
}
}
var exports = module.exports = adm
我正在使用 node.js 和 nw.js 创建 Web 应用程序 现在我正在导出以下模块
admin.js
module.exports = function (firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.fullName = function () {
return this.firstName + ' ' + this.lastName;
}}
and trying to access it in login.js file
var adm= require('./model/admin.js');
var adms=new adm("hi","wow");
adms.fullName();
But it says adm is not a constructor
你的代码看起来很棒。
也许可以尝试更改您的 admin.js,但通常您的代码应该可以工作
var adm = function (firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.fullName = function () {
return this.firstName + ' ' + this.lastName;
}
}
var exports = module.exports = adm