gamesys / moonshine

A lightweight Lua VM for the browser
http://moonshinejs.org
MIT License
501 stars 35 forks source link

'use strict' and var shine = shine || {}; #42

Open bmcbarron opened 7 years ago

bmcbarron commented 7 years ago

Howdy! I'm enjoying moonshine, thank you!

I see that several files use the idiom:

'use strict'
var shine = shine || {};

In Chrome, this results in:

var shine;           // implicitly undefined
shine = shine || {}; // ... therefore always {}

Thus, you can't use this technique to augment the same object (e.g. including moonshine.js and distillery.moonshine.js together).

This is further confused because in moonshine.js, 'use strict' is not the first line of code, so it actually has no effect. Things sometimes work as intended, depending on the exact mechanism used to include those two files.

I verified two possible ways of fixing this: 1) Remove 'use strict'. 1) Use var shine = this.shine = this.shine || {};

If you pursue the second case, I recommend moving 'use strict'; to the top of moonshine.js, to get the intended effect.

Cheers, and thanks again!

paulcuth commented 7 years ago

Hi,

Sorry for not picking this up sooner. Thanks for the spot!

I see you've fixed it in your fork. I agree that option 2 is the best solution; if you'd like to create a pull request, I'd be pleased to merge it back upstream.

Regards, Paul.