获得JavaScript的阵列的方法列表 [英] get list of methods in JavaScript's Array
问题描述
var c=$('<canvas></canvas>')[0].getContext('2d')
for(m in c){console.log(m)}
本打印的CanvasRenderingContext2D方法的列表。我该怎么办了一个数组一样。我想要得到拼接,流行,推等。显然为(以Array.prototype米){执行console.log(M)}
荣获'将不起作用。
This prints a list of methods in CanvasRenderingContext2D. How can I do the same for an Array. I want to get "splice", "pop", "push", etc. Obviously for(m in Array.prototype){console.log(m)}
won't work.
推荐答案
大多数方法和内置对象内部被标记为不可枚举的,所以他们不会在一个枚举的属性用户资格在
循环。
Most methods and properties of built-in objects are internally marked as non-enumerable, so they will not be enumerated in a for-in
loop.
5的ECMAScript有<一个href=\"https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames\"><$c$c>Object.getOwnPropertyNames$c$c>方法,返回所有属性名的数组,所以你可以这样做:
ECMAScript 5 has an Object.getOwnPropertyNames
method that returns an array of all property names, so you can do:
Object.getOwnPropertyNames(Array.prototype)
但并不是所有浏览器都支持呢。
but this isn't supported by all browsers yet.
这篇关于获得JavaScript的阵列的方法列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!