创建纯空Object
ie9和其它浏览器可以用Object.create(null)纯空对象,没有任何成员的,IE的旧版本可以使用以下代码模拟,但需要维持doc的引用
//IronJS-上官荔枝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 }())
测试代码:
({}).toString Object.create(null).toString
机器瞎学/数据掩埋/模式混淆/人工智障/深度遗忘/神经掉线/计算机幻觉/专注单身二十五年