enb / enb-bem-i18n

BEM internationalization for ENB
Other
8 stars 7 forks source link

fix global object reference for node #81

Closed mykolaharmash closed 8 years ago

mykolaharmash commented 9 years ago

In global scope this is reference to module.exports not to global

arikon commented 9 years ago

@snater It should not be a global in node environment.

arikon commented 9 years ago

/cc @blond

mykolaharmash commented 9 years ago

@arikon then defineAsGlobal is pointless in node. How should I define I18N for global BEM? Passing globals: 'force' to tech doesn't work either, because var BEM; added as first line.

blond commented 8 years ago

In global scope this is reference to module.exports not to global

It is not true:

this === global // true
this === module.exports // false

@snater, can you give me a real example?

How should I define I18N for global BEM? Passing globals: 'force' to tech doesn't work either, because var BEM; added as first line.

BEM will be provide to global.BEM in case of using option exports: { globals: 'force' }. See https://github.com/snater/enb-bem-i18n/blob/master/techs/i18n.js#L106.

Docs for option exports.

mykolaharmash commented 8 years ago

Sorry, I mean module scope, not global

// test-module.js
console.log(this === global);
console.log(this === module.exports);
node -e "require('./test-module.js')"
false
true
blond commented 8 years ago

@snater Thanks!