
Modifying built-in protypes such as Object.prototype is considered harmful. For backward compatibility with legacy user scripts and gadgets, many wg-prefixed configuration keys are still defined as global varables as well, but these are deprecated. Note that configuration variables exposed by MediaWiki must be accessed via mw.config. To publicly expose functionality for re-use, use module.exports from Package files, and/or assign properties within the mw hierarchy, e.g. For example, built-in globals such as String or Object must not be extended with additional utility methods, and similarly functionality relating to OOjs or jQuery, should not be assigned to those globals. Avoid modifying globals not "owned" by your code.

In addition to browser globals, the only globals that are safe to use are mw, $ and OO.Īvoid creating new global variables. This improves confidence in code through static analysis and may also power other IDE features. Use globals exposed by the browser (such as document, location, navigator) directly and not as properties of the window object.

Avoid the substr(), or substring() methods which are redundant, easily mistaken, and may have unexpected side effects. To extract part of a string, use the slice() method for consistency. Remember there are no "magic quotes" in JavaScript i.e.

Use single quotes instead of double quotes for string literals. Global variables: typeof variable = 'undefined'.

