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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -