0
これはfoo.js
という名前のファイル内のスクリプトです。ノードシェルで 'this'とは何が定義されていますか?
console.log(this === module.exports)
これは、期待される出力、すなわちtrue
を与える。
$ node foo.js
true
$ node
> require('./foo')
true
{}
しかし、私は次のように反対の出力、すなわちfalse
を生産する理由を理解することができません。
$ node
> console.log(this === module.exports)
false
undefined
> .load foo.js
> console.log(this === module.exports)
false
undefined
ノードシェルではthis
と定義されていますか?
グローバルオブジェクト 'global' – Ryan
コンソールに 'this'と入力してEnterキーを押してみてください。 :-) –
[node.jsはブラウザのウィンドウオブジェクトに相当しますか?](https://stackoverflow.com/questions/19849136/does-node-js-have-equivalent-to-window-object-in) -browser) – lifeisfoo