lfe*_*445 2 javascript arrays iteration object javascript-objects
我想对数组对象上可用的方法进行自省
> console.log(Array.prototype)
[]
undefined
> console.log(Array.prototype.push)
[Function: push]
Run Code Online (Sandbox Code Playgroud)
我如何查看或记录对象原型上可用的所有属性/方法?
您可以使用.getOwnPropertyNames()which返回所有属性名称(包括不可枚举的属性)的数组:
const PrintAll = obj => console.log(Object.getOwnPropertyNames(obj));
PrintAll(Array.prototype);Run Code Online (Sandbox Code Playgroud)
.as-console-wrapper { max-height: 100% !important; top: 0; }Run Code Online (Sandbox Code Playgroud)