私は今nodejsを学んだし、Imはどのように思って、私は、例えば、他のファイルNodejs他のファイルからクラスオブジェクトへの参照
で作成したオブジェクトに参照することができます。 私は私のクラスユーザーとファイルを持っています。私は
module.exports = class Username {
constructor(name, lastProjects) {
this.current.name = name;
this.current.lastProjects = lastProjects;
}
};
name.handler.jsを輸出していますJS私はそれ、これはファイル
const Alexa = require('alexa-sdk');
const User = require('../models/user.model');
module.exports = Alexa.CreateStateHandler(StatesConst.NAME, {
'NewSession': function() {
this.emit('NewSession'); // Uses the handler in newSessionHandlers
},
'MyNameIsIntent': function() {
var user = new User.Username("Anna", ["project1", "project2"]);
this.emit(':ask', "Hi "+User.Username.name);
}
}
をオーデルにエクスポートすることはできません
user.handler.js私はtottaly私は私のprogramm内の他のファイルに新しいユーザーオブジェクトに参照することができますどのように私の新しい作成されたオブジェクトのユーザー名
const Alexa = require('alexa-sdk');
const User = require('../models/user.model');
module.exports = Alexa.CreateStateHandler(StatesConst.NEWSTATE, {
'NewSession': function() {
this.emit('NewSession'); // Uses the handler in newSessionHandlers
},
'MyUserIntent': function() {
this.emit(':ask', "My username is "+User.Username.name);
}
}
への参照を書くことができる方法を知っていけませんか?私はユーザーがプログラムを開始するたびに新しいユーザーオブジェクトを取得し、他のすべてのファイルの属性を参照および変更できるようにしたいと思います。私は非常に助け:)メッセージ=を取得する場合
、文は
require('../models/user')
ようになるはずではない必要がCannot read property 'name' of undefined
を得るのだろうか? – error404