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-2/

Prototype Adapter Utility

Implement small helpers that reassign or clone objects with a specified prototype using the compatibility helper provided by the dependency package. Utilities should work with ordinary prototype objects as well as null prototypes, preserving existing own properties and TypeScript typing for callers.

Capabilities

Reassigns prototype on existing object

  • Given a target { role: "guest" } and a prototype object { describe() { return "role:" + this.role; } }, the helper updates the target in place so that Object.getPrototypeOf(result) equals the provided prototype, returns the same reference, and result.describe() produces role:guest. @test

Supports null prototypes

  • With a target { color: "blue" } and a null prototype, the helper returns the same reference, Object.getPrototypeOf(result) is null, and existing properties remain accessible after the change. @test

Clones with alternate prototype

  • Cloning a source { id: 7 } with a prototype { prefix: "id" } yields a new object with a different reference, prototype set to the provided object, inherited prefix, and leaves the original source prototype unchanged. @test

Respects existing own properties

  • If the prototype supplies { label: "fallback", status: "pending" } while the target is { label: "explicit" }, applying the prototype keeps the label value as "explicit" and exposes status via the prototype. @test

Implementation

@generates

API

export function attachPrototype<T extends object>(target: T, proto: object | null): T;
export function cloneWithPrototype<T extends object>(source: T, proto: object | null): T;

Dependencies { .dependencies }

setprototypeof { .dependency }

Provides a cross-runtime prototype assignment helper.

Install with Tessl CLI

npx tessl i tessl/npm-setprototypeof

tile.json