https://bugzilla.wikimedia.org/show_bug.cgi?id=73011

Krinkle <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID
            Summary|referenceError for          |resourceloader: Function
                   |userdefined javascript      |defined javascript function
                   |functions                   |does not exist in global
                   |                            |scope

--- Comment #2 from Krinkle <[email protected]> ---
Executing files in the global scope is considered an anti-pattern in modern web
development and causes all kinds of interoperability and maintenance problems.

ResourceLoader modules are wrapped in a closure (one step away from global in
lexical scoping) to discourage use of global variables.

Variables and functions are local to the module by default, not global for the
entire browser execution context.

To expose a method or property to the public (e.g. so that other modules can
reference them), attach them to a host object (e.g. jQuery, mediaWiki or your
own application singleton).

e.g.

-- extensions/MyApp/foo.js

mw.foo = function () { return 4; };
// or:
window.MyApp = {};
MyApp.foo = function () { return 4; };

These will all be exposed and accessible from the global scope.

-- extensions/OtherApp/bar.js
-- dependencies: ext.myApp.foo

alert(mw.foo());

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to