On Thu, Aug 20, 2015 at 7:26 AM, Bartosz Dziewoński <[email protected]>
wrote:

When you load a script through ResourceLoader, it's not executed in global
> context. This means that global variables you define are actually *not
> global* (they are local to the function your code is wrapped in), unless
> you explicitly assign them as `window` properties.
>

I added a section on this, "Global variables are not global" to
https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide under
MediaWiki 1.26,
with a pointer to
https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Globals
where the latter says "Only mediaWiki
<https://www.mediawiki.org/wiki/RL/DM#MediaWiki> and jQuery
<https://www.mediawiki.org/wiki/RL/DM#jQuery> should be used (in addition
to the browser's native APIs)."

The latter doesn't suggest creating an object with mediaWiki/mw. I added

You should expose your code's functionality to other clients as functions
> and properties of an object within mediaWiki, e.g. mediaWiki.echo, and
> possibly as documented mw.config configuration variables.
>

but surely there's a page that talks about this idiom. Are there any
gadgets that add an object within mediaWiki ? If we were to rewrite
morebits.js from scratch, wouldn't it be better to create
mediaWiki.moreBits.{quickForm, simpleWindow, ...} rather than
window.MoreBits ?

Cheers,
-- 
=S Page  WMF Tech writer
_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to