Skip to content

Instantly share code, notes, and snippets.

@leecade
Forked from WebReflection/inherit.js
Created December 28, 2012 19:23
Show Gist options
  • Select an option

  • Save leecade/4401057 to your computer and use it in GitHub Desktop.

Select an option

Save leecade/4401057 to your computer and use it in GitHub Desktop.
/*!(C) WebReflection *//** @license Mit Style */
// inspired by https://gist.github.com/4395291
this.inherit || (this.inherit = function(create){
if (!create) {
if ({__proto__:null} instanceof Object) {
for (var
Null = function Null() {},
doc = document,
html = doc.documentElement,
iframe = html.insertBefore(
doc.createElement("iframe"),
html.lastChild
),
idoc = iframe.contentWindow.document ||
iframe.contentDocument ||
iframe.document,
NullPrototype = Null.prototype = (
idoc.open(),
idoc.write(
'<script>parent.inherit=Object.prototype<' +
'/script>'
),
idoc.close(),
inherit
),
xtend = function xtend(object) {
return xtend.prototype === object ?
(xtend.prototype = xtend, this) :
new xtend(xtend.prototype = object)
;
},
iframe = html.removeChild(iframe),
proto = [
"hasOwnProperty",
"isPrototypeOf",
"propertyIsEnumerable",
"valueOf",
"toString",
"toLocaleString",
"constructor"
],
i = proto.length; i--;
) delete NullPrototype[proto[i]];
// you know ... IE, leaks, and shit ...
create = iframe = html = doc = proto = NullPrototype =
function(object) {
return object == null ? new Null : xtend(object);
}
;
} else {
create = function(object) {
return {__proto__: object};
};
}
}
return function(object) {
return create(object);
};
}(Object.create));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment