3 ms·
Reassigning the `exports` variable does not change the return value of `require`. The return value of `require` is `module.exports`, which may be reassigned.
by strager 14y ago
Reassigning the `exports` variable does not change the return value of `require`.
The return value of `require` is `module.exports`, which may be reassigned.
Initially, the global `exports` variable is set to the same value as `module.exports`. Writing `exports = module.exports = ...` ensures they have the same value as you would expect.
- tferris 14y ago> Writing `exports = module.exports = ...` ensures they have the same value as you would expect. But where should they have the same value? I thought require returns just module.exports if it exists and ignores exports.
- secoif 14y ago'this' is also the same as exports. Initially, they all have the same value, they all point at the same object. If you assign module.exports to a new object (vs simply adding properties to the existing object) it will ignore the value of exports and this. It's incredibly confusing and they should have just picked one way to export data, instead of three.