Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I iterate over Array.prototype functions

I want to wrap all Array functions in array object, but in console

>>> Array.prototype
[]
>>> [].prototype
undefined

but when I type Array.prototype in console it show all functions in autocomple, how can I get those functions? Where are they hidden?

like image 354
jcubic Avatar asked Sep 12 '12 08:09

jcubic


2 Answers

do you mean:

var arrObj = Object.getOwnPropertyNames(Array.prototype);
for( var funcKey in arrObj ) {
   console.log(arrObj[funcKey]);
}
like image 97
Sudhir Bastakoti Avatar answered Nov 05 '22 23:11

Sudhir Bastakoti


Using ECMAScript 6 (ECMAScript 2015), you can simplify a bit:

for (let propName of Object.getOwnPropertyNames(Array.prototype)) {
   console.log(Array.prototype[propName]);
}
like image 33
Peter Tseng Avatar answered Nov 05 '22 21:11

Peter Tseng