javascript - TypeError: Cannot set property of undefined in module.exports -
'use strict'; module.exports = function () { this.myvar = 'example'; console.log(this.myvar); }; i error:
/home/karl/mymodule.js:3 this.myvar = 'example'; ^ typeerror: cannot set property 'myvar' of undefined
in strict mode, this undefined.
but in non-strict mode this nothing pointing global.
so here, trying set on undefined, error
where exactly, intending attach myvar ?
on module ? or on global ? if on global (which bad idea), use global.myvar or global.myvar.
if on module module.exports.myvar = 'example';
Comments
Post a Comment