Skip to content

noExtendNative

biome.json
{
"linter": {
"rules": {
"nursery": {
"noExtendNative": "error"
}
}
}
}

Disallow extending the prototype of built-in objects.

Adding properties to the prototype of a built-in such as Object, Array, or Error leaks into every value of that type. The new property shows up in every for...in, collides with other libraries that patch the same prototype, and breaks assumptions across the whole program. Extend a subclass or use a standalone helper instead.

This rule flags a direct prototype assignment (Builtin.prototype.x = ...), computed prototype access (Builtin["prototype"].x = ...), and Object.defineProperty/Object.defineProperties targeting a built-in prototype.

Object.prototype.extra = "a";
code-block.js:1:1 lint/nursery/noExtendNative ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid extending the prototype of ‘Object’.

> 1 │ Object.prototype.extra = “a”;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Patching a native prototype leaks the property into every value of that type and can collide with other code.

Use a subclass or a standalone helper instead.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Array.prototype.times = function () {};
code-block.js:1:1 lint/nursery/noExtendNative ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid extending the prototype of ‘Array’.

> 1 │ Array.prototype.times = function () {};
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Patching a native prototype leaks the property into every value of that type and can collide with other code.

Use a subclass or a standalone helper instead.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Object.defineProperty(Array.prototype, "times", { value: 999 });
code-block.js:1:1 lint/nursery/noExtendNative ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid extending the prototype of ‘Array’.

> 1 │ Object.defineProperty(Array.prototype, “times”, { value: 999 });
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Patching a native prototype leaks the property into every value of that type and can collide with other code.

Use a subclass or a standalone helper instead.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

class CustomArray extends Array {}
const obj = {};
obj.extra = "a";