CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-setprototypeof

A small polyfill for Object.setPrototypeOf with cross-platform compatibility

82

1.02x
Overview
Eval results
Files

task.mdevals/scenario-1/

Prototype Rebinding Utility

Create a small helper that switches an object's prototype using the provided compatibility dependency so that behavior can be shared across runtimes without manual property copying.

Capabilities

Reassigns prototype for behavior reuse

  • When given a plain object { name: "Ada" } and a prototype containing greet() { return "hi " + this.name; }, the helper updates the object's prototype so Object.getPrototypeOf(result) equals the prototype object, result.greet() returns "hi Ada", and the returned reference is the original object. @test

Supports null prototype

  • Passing null as the new prototype results in an object whose prototype is null while preserving existing own properties (e.g., id: 42). @test

Rejects invalid prototypes

  • Supplying a non-object, non-null prototype (e.g., a number) throws a TypeError before any mutation occurs. @test

Implementation

@generates

API

/**
 * Rebinds the prototype of the target object to the provided prototype.
 * @param {object} target - Object whose prototype will be changed.
 * @param {object|null} newPrototype - Prototype to apply, or null for objects without a prototype.
 * @returns {object} The same target object after rebinding.
 * @throws {TypeError} If target is not an object or newPrototype is neither an object nor null.
 */
function rebasePrototype(target, newPrototype);

module.exports = { rebasePrototype };

Dependencies { .dependencies }

setprototypeof { .dependency }

Runtime-compatible prototype rebinding utility used to adjust an object's prototype without reimplementing low-level behaviors.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-setprototypeof

tile.json