precision-game/js/underride.mjs

31 lines
552 B
JavaScript
Raw Normal View History

2023-10-25 19:33:24 +00:00
import { assert } from "./test.mjs";
function shallow_mutable_copy (source, target) {
for (const [key, value] of Object.entries(source)) {
target[key] = value;
}
}
export function underride (object, template) {
const result = {};
shallow_mutable_copy(template, result);
shallow_mutable_copy(object, result);
return result;
}
assert("underriding works.", _ => {
const object = underride({
gay: true,
trans: true,
}, {
trans: false,
invisible: false,
});
return object.gay && object.trans && (object.invisible === false);
});