src/content/docs/linter/rules/no-proto.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.8` - Diagnostic Category: [`lint/nursery/noProto`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`no-proto`](https://eslint.org/docs/latest/rules/no-proto){
"linter": {
"rules": {
"nursery": {
"noProto": "error"
}
}
}
}
Disallow the use of the deprecated __proto__ object property.
Object.prototype.__proto__
is a special accessor used to get or set the prototype of an object. \
However, it has been deprecated since ECMAScript 2009, being much slower and much less reliable than its
modern counterparts Object.getPrototypeOf()
and Object.setPrototypeOf().
Since it is a regular property on Object.prototype,
__proto__ will not work on null-prototype objects that do not extend from Object.prototype
nor ones having created their own __proto__ properties via Object.defineProperty.
As such, this rule encourages the use of Object.getPrototypeOf() and Object.setPrototypeOf()
in lieu of directly accessing __proto__.
:::info
Note that this does not check for the use of __proto__ inside object literal definitions
to set a newly created object's prototype,
which is standard practice and well-optimized in modern browsers. :::
obj.__proto__ = a;
const b = obj.__proto__;
const a = Object.getPrototypeOf(obj);
Object.setPrototypeOf(obj, b);
// This sets `foo`'s prototype to `null` (similar to `Object.create`), and is
// well-defined across browsers.
const foo = {
__proto__: null,
a: 1,
}