Created
August 26, 2012 18:22
-
-
Save hax/3482308 to your computer and use it in GitHub Desktop.
How to create a naked Object in old Browsers (eg. IE 6,7,8) which not support Object.create(null) or {__proto__: null}
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
function nakedObject() { | |
var iframe = document.createElement('iframe') | |
iframe.width = iframe.height = 0 | |
iframe.style.display = 'none' | |
document.appendChild(iframe) | |
iframe.src = 'javascript:' | |
var proto = iframe.contentWindow.Object.prototype | |
iframe.parentNode.removeChild(iframe) | |
iframe = null | |
var props = [ | |
'constructor', 'hasOwnProperty', 'propertyIsEnumerable', | |
'isPrototypeOf', 'toLocaleString', 'toString', 'valueOf' | |
] | |
for (var i = 0; i < props.length; i++) { | |
delete proto[props[i]] | |
} | |
return proto | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment