Getting a list of available functions for a class in Node.js

I am trying to find a simple and easy way to just get a list of available functions for a class in Node.js using the command line.

Based on previous searches on the Internet, I came across Object.getOwnPropertyNames(), but it seems that this function is inconsistent, otherwise I do not understand why it works for some classes, but not for others.

Let me work through an example and maybe someone can help. Node -v is currently outputting v4.4.5 for this example.

First, suppose I wanted to get a list of functions for the Math class. From the node console, this works fine, I get:

[root@localhost /]# node
> Object.getOwnPropertyNames(Math)
[ 'E',
  'LN10',
  'LN2',
  'LOG2E',
  'LOG10E',
  'PI',
  'SQRT1_2',
  'SQRT2',
  'random',
  'abs',
  'acos',
  'asin',
  'atan',
  'ceil',
  'exp',
  'floor',
  'log',
  'round',
  'sqrt',
  'atan2',
  'pow',
  'max',
  'min',
  'imul',
  'sign',
  'trunc',
  'tanh',
  'asinh',
  'acosh',
  'atanh',
  'hypot',
  'fround',
  'clz32',
  'cbrt',
  'cos',
  'sin',
  'tan',
  'sinh',
  'cosh',
  'log10',
  'log2',
  'log1p',
  'expm1' ]
>

Cool. It works.

, Node.js , , , " " Node.js: http.Server

:

> Object.getOwnPropertyNames(http.Server)
[ 'length', 'name', 'prototype', 'super_' ]

Hmmm.... , , , server.close(), server.listen(). , net.Server, , , . , :

> Object.getOwnPropertyNames(net.Server)
[ 'length', 'name', 'prototype', 'super_' ]

... net.Server, , server.address(), server.getConnections() .

- :

(a) getOwnPropertyNames, , , , ... (b) "" Node.js, API ?

+4
1

docs getOwnPropertyNames, :

, . Object.keys() for... in ( , , , , hasOwnProperty()).

, getOwnPropertyNames(), Object.keys() .

, , , , . :

for (var prop in obj) {
    console.log('obj.' + prop + ' = ' + obj[prop]);
}

. , , , .

0
source

Source: https://habr.com/ru/post/1655899/


All Articles