This is a simple demo of how latest Bun could've implemented .as(Class)
instead of using the quite jurassic Object.create
which is slow, bloated due descriptors logic, if used at all, and incapable to play nicely with features introduced after Object.create
was even specified.
// what `as(Class)` should return
const { assign } = Object;
const asClass = new WeakMap;
const setAsClass = Class => {
class As extends Class {
constructor(fields) {
assign(super(), fields);