Last active
May 7, 2016 08:18
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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