osephp.blogg.se

Javascript coding
Javascript coding













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.

javascript coding

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.

javascript coding

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.

javascript coding

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

javascript coding

  • HTMLElement: obj.nodeType = Node.ELEMENT_NODE.
  • Plain Object: jQuery.isPlainObject( val ).
  • Use strict equality operators ( = and !=) instead of (loose) equality ( = and !=).
  • Primitive types and special values: boolean, number, string, undefined, null.īuilt-in classes: Object, Array, Function, Date, RegExp, Error. (used when a configuration object is passed to the class constructor, use one for each property and don't include those of parent constructors)















    Javascript coding