Skip to content

Instantly share code, notes, and snippets.

@jido
Last active May 7, 2016 08:18
Show Gist options
  • Save jido/8a1424dd6fd3e170e75572257c96b26c to your computer and use it in GitHub Desktop.
Save jido/8a1424dd6fd3e170e75572257c96b26c to your computer and use it in GitHub Desktop.
Why does this give a TypeError: cannot convert undefined or null to object?
"use strict";
function copy(proto, changes) {
if (changes === undefined) return Object.create(proto);
var props = Object.keys(changes).map(function(attr) {
var single = {};
single[attr] = {value: changes[attr], writable: false, enumerable: true};
return single;
});
return Object.create(proto, Object.assign.apply(props));
}
var c = {r: 0, g: 0, b: 0};
copy(c, {r: 1, b: 1});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment