import { assertEquals } from "jsr:@std/assert"
const
array_proto = prototypeOfClass(Array<number>),
arr = [1, 2, 3, 4, 5]
array_proto.push.call(arr, 6)
assertEquals(arr, [1, 2, 3, 4, 5, 6])
const slow_push_to_arr = (...values: number[]) => (arr.push(...values))
// the following declaration is more performant than `slow_push_to_arr`,
// and it also has lower memory footprint.
const fast_push_to_arr = array_proto.push.bind(arr)
slow_push_to_arr(7, 8) // sloww & bigg
fast_push_to_arr(9, 10) // quicc & smol
assertEquals(arr, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
get the prototype object of a class.
this is useful when you want to access bound-methods of an instance of a class, such as the ones declared as:
these bound methods are not available via destructure of an instance, because they then lose their
this
context. the only functions that can be destructured without losing theirthis
context are the ones declared via assignment: