Jump to content

User:Jeblad/Javascript and Mediawiki/use strict

From mediawiki.org

use strict is a pragma to tell the Javascript interpreter that is should shift from a forgiving execution model to a stricter one, and to prevent certain actions from being taken. If previously deprecated language features are found they may either simply be disabled or the interpreter may throw an error. Several features will change and the resulting new execution environment can be incompatible for a previously functional code.


Note that the ResourceLoader can add an outer function call and this may influence scooping of the use strict pragma.

Global level pragma
If the use strict pragma is added before any other code in the script the complete script will use strict mode.
"use strict";
Function level pragma
If the use strict pragma is added before any other code in a function all code in the function will use strict mode.
function () {
    'use strict';
}