3 ms·
To mitigate it, use `null` as prototype: Object.create(null) For example, function PersonModel(person) { const p = Object.assign(Object.create
by efortis 3y ago
To mitigate it, use `null` as prototype:
Object.create(null)
For example,
function PersonModel(person) {
const p = Object.assign(Object.create(null), person)
p.name ??= ''
p.age ??= 0
return p
}
const p1 = PersonModel(JSON.parse('{"__proto__": { "Mallory": 666 }}'))
p1.Mallory // undefined