Skip to content

Instantly share code, notes, and snippets.

@hax
Created August 26, 2012 18:22
Show Gist options
  • Save hax/3482308 to your computer and use it in GitHub Desktop.
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}
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