获取JavaScript的Array中的方法列表

pit*_*itr 6 javascript arrays

var c=$('<canvas></canvas>')[0].getContext('2d')
for(m in c){console.log(m)}
Run Code Online (Sandbox Code Playgroud)

这将在CanvasRenderingContext2D中打印方法列表.我怎样才能对数组做同样的事情.我想得到"拼接","流行","推"等等.显然是for(m in Array.prototype){console.log(m)}行不通的.

cas*_*nca 13

内置对象的大多数方法和属性在内部标记为不可枚举,因此它们不会在for-in循环中枚举.

ECMAScript 5有一个Object.getOwnPropertyNames返回所有属性名称数组的方法,因此你可以这样做:

Object.getOwnPropertyNames(Array.prototype)
Run Code Online (Sandbox Code Playgroud)

但尚未得到所有浏览器的支持.