A small polyfill for Object.setPrototypeOf with cross-platform compatibility
82
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.
{ 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. @testnull as the new prototype results in an object whose prototype is null while preserving existing own properties (e.g., id: 42). @testTypeError before any mutation occurs. @test@generates
/**
* 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 };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