Node.jsを使用して、次のように記述app.js
した場合:
var commons = {
title: 'myTitle',
description: 'MyDesc',
menu: {
home: {
label: 'Home',
url: '/',
},
contacts: {
label: 'Contacts',
url: '/contacts'
}
}
}
console.log(commons);
私はこの出力をしました...
{
title: 'myTitle',
description: 'MyDesc',
menu: {
home: {
label : 'Home',
url: '/'
},
contacts: {
label: 'Contacts',
url: '/contacts'
}
}
}
...そしてそれはうまくいきます。app.js
しかし、 (同じパスにある)別のファイルから変数をロードする場合...
commons.js
:
exports.commons = {
title: 'myTitle',
description: 'MyDesc',
menu: {
home: {
label: 'Home',
url: '/',
},
contacts: {
label: 'Contacts',
url: '/contacts'
}
}
}
app.js
:
var commons = require('./commons');
console.log(commons);
私は出力として持っています:
commons: {
{
title: 'myTitle',
description: 'MyDesc',
menu: {
home: [Object],
contacts: [Object]
}
}
}
なぜこうなった?2つのファイル間で変数を正しく渡すにはどうすればよいですか?