在编写JavaScript时,我经常忘记一些内置对象的属性,并且必须在mdn中查找它们,这很烦人,因为它会减慢我的工作。任何方式来遍历所有的非枚举属性?
而不是参考文档,创建一个对象并使用for ... in
检查console.log()
更方便。但是当涉及到非枚举属性时,即使for ... in
也无济于事。
所以我的问题是,除了谷歌和文件,有没有办法检查非枚举属性?
for(var i in Object){
console.log([i,Object[i]]);
// ["wtbind", function()]
}
console.log(Object.hasOwnProperty('create'));
// true
// Here Object.create is a non–enumerable property,
// and I have to look it up in documents if I forget it.
你用什么浏览器进行开发?你有没有考虑'console.dir()'而不是'console.log()'? – lanzz
不可枚举是否禁用使用Object.toSource();的能力? – Steve
@lanzz firefox和萤火虫。我不知道有一个'console.dir()'。我试过'console.dir(Object); //显示“prototype Object {}”',但那些不可枚举的属性如Object.create没有显示出来。 – Rufus