Created
May 9, 2011 14:52
-
-
Save satyr/962661 to your computer and use it in GitHub Desktop.
`Object.create(null)` for JScript
This file contains hidden or 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
// `Object.create(null)` for JScript. | |
// Based on @bga_'s SafeJS. | |
NullObject = (function(){ | |
var doc = new ActiveXObject('htmlfile') | |
doc.write('<script><\/script>') | |
doc.close() | |
var Obj = doc.parentWindow.Object | |
if(!Obj || Obj === Object) return | |
var name, names = | |
[ 'constructor', 'hasOwnProperty', 'isPrototypeOf' | |
, 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf'] | |
while(name = names.pop()) if(!delete Obj.prototype[name]) return | |
return Obj | |
}()) | |
!function(){ | |
var toString = 1 | |
with(new NullObject) WSH.echo(toString) | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment