-
-
Save WebReflection/9900019 to your computer and use it in GitHub Desktop.
if the only reason you like __proto__ is its literal integration, just use this and make the web better today. No credits needed
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
// ES5 dirty perf oriented tweet size | |
var O=function(O,s){s=O.setPrototypeOf||function(o,p){o.__proto__=p;return o};return function(p,o){return o?s(o,p):p||s({},p)}}(Object); | |
// ES5 dirty performance way | |
var O = function(Object){ | |
var | |
create = Object.create, | |
set = Object.setPrototypeOf || function(o, p) { | |
o.__proto__ = p; | |
return o; | |
}, | |
undefined | |
; | |
return function (p, o) { | |
return o === undefined ? ( | |
p === null ? create(p) : p | |
) : set(o, p); | |
}; | |
}(Object); | |
// ES5 full compliant way | |
var O = function(Object){ | |
var | |
oProto = Object.prototype, | |
create = Object.create, | |
has = oProto.hasOwnProperty, | |
undefined | |
; | |
return function (p, o) { | |
var r, k; | |
if (o === undefined) { | |
o = p; | |
p = p === null ? p : oProto; | |
} | |
r = create(p); | |
for (k in o) { | |
if (has.call(o, k)) { | |
r[k] = o[k]; | |
} | |
} | |
return r; | |
}; | |
}(Object); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
examples