-
-
Save rlamana/5501219 to your computer and use it in GitHub Desktop.
This file contains 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
var extend = Object.getOwnPropertyNames ? | |
function ecma5extend(obj) { | |
var proto = obj; | |
var protos = []; | |
var result = {}; | |
while (proto) { | |
protos.push(proto); | |
proto = Object.getPrototypeOf(proto); | |
} | |
protos.reverse().forEach(function(ancestor) { | |
Object.getOwnPropertyNames(ancestor).forEach(function(prop) { | |
var descriptor = Object.getOwnPropertyDescriptor(ancestor, prop); | |
Object.defineProperty(result, prop, descriptor); | |
}); | |
}); | |
return result; | |
} : | |
function fallback(obj) { | |
var result = {}; | |
for (var i in obj) | |
result[i] = obj[i]; | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment