Object.assign Polyfill

ObjectsPolyfill

Implement Object.myAssign(target, ...sources).

Requirements:

  • Throw TypeError if target is null or undefined
  • Skip null/undefined sources silently
  • Copy own enumerable properties — both string keys and symbol keys
  • Mutate and return the target
  • This is a shallow copy — nested objects are copied by reference

Examples

Example 1
Input
Object.myAssign({ a: 1 }, { b: 2 }, { c: 3 })
Output
{ a: 1, b: 2, c: 3 }
Explanation
Properties from all sources are merged into the target.
Example 2
Input
const sym = Symbol('x');
Object.myAssign({}, { [sym]: 42 })
Output
{ [Symbol(x)]: 42 }
Explanation
Symbol keys are copied — use Reflect.ownKeys, not Object.keys.

Constraints

  • Use `Reflect.ownKeys` to capture symbol keys
  • Check `descriptor.enumerable` before copying

Notes

  • Later sources overwrite earlier ones for the same key

Hints

Read the full write-up for Object.assign Polyfill
</>JavaScript
Loading editor…
Test Result
Run your code, or Submit to test it