objectProto
Reports using the deprecated proto property to access or modify an object's prototype.
✅ This rule is included in the ts untyped
preset.
The __proto__
property is a deprecated way to access and modify an object’s prototype.
While it is supported for backwards compatibility, it is not part of the ECMAScript standard and can cause performance issues.
Direct manipulation of an object’s prototype can lead to “hidden classes” in JavaScript engines, resulting in slower code execution.
Examples
Section titled “Examples”const proto = obj.__proto__;
obj.__proto__ = prototype;
const value = obj["__proto__"];
const proto = Object.getPrototypeOf(obj);
Object.setPrototypeOf(obj, prototype);
const obj = Object.create(prototype);
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you need to support very old JavaScript environments that don’t have Object.getPrototypeOf
and Object.setPrototypeOf
(pre-ES5), you might need to disable this rule.
However, this is extremely rare in modern development, as even Internet Explorer 9 supports these methods.
Further Reading
Section titled “Further Reading”- MDN: Object.prototype.proto
- MDN: Object.getPrototypeOf()
- MDN: Object.setPrototypeOf()
- MDN: Object.create()
Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
no-proto
- Oxlint:
eslint/no-proto
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.