JSLint and JSHint will throw the "Read only" error when they encounter an attempt to assign a value to built-in native object. In the following example we attempt to overwrite String constructor function:
As of July 2013, JSLint will also throw the "Read only" error when it encounters an assignment to an exception parameter. This previously generated the "Do not assign to the exception parameter" warning. See the page for that message for more details on the reasoning behind it:
This error is raised to highlight a potentially dangerous piece of code. Your code will may fine if you do not fix this error, but it may be confusing to others, especially at first glance to someone quickly searching through your script, and it may break third party scripts.
It is perfectly valid to overwrite any of the native built-in functions, but there are limited use cases for it. JSLint and JSHint both forbid this practice completely and do not provide an option to allow it.
The list of read only functions used by JSLint is as follows:
Array | Boolean | Date | decodeURI | decodeURIComponent | encodeURI | encodeURIComponent |
Error | eval | EvalError | Function | isFinite | isNaN | JSON |
Math | Number | Object | parseInt | parseFloat | RangeError | ReferenceError |
RegExp | String | SyntaxError | TypeError | URIError |
JSHint uses the same list, but adds a few extra identifiers to it:
hasOwnProperty | Map | NaN | Set | WeakMap |
In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. The identifier of this warning is W020. This means you can tell JSHint to not issue this warning with the /*jshint -W020 */
directive.