Javascript 相当于Python';节点REPL中的s dir()?

Javascript 相当于Python';节点REPL中的s dir()?,javascript,node.js,read-eval-print-loop,Javascript,Node.js,Read Eval Print Loop,我正在使用Uint8Array。我不习惯使用Uint8Array 如果这是Python: >>> a = [1, 2, 3] >>> dir(a) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__get

我正在使用
Uint8Array
。我不习惯使用
Uint8Array

如果这是Python:

>>> a = [1, 2, 3]
>>> dir(a)
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> help(a.pop)
< ... shows helpful function documentation ... >
嗯,StackOverflow建议:

我想不会吧


在节点的shell环境中是否有类似的方法来检查这样的对象?

之后按TAB键:

> a = new Uint8Array([1, 2, 3])
Uint8Array { '0': 1, '1': 2, '2': 3 }
> a. <<TAB>>
a.__defineGetter__      a.__defineSetter__      a.__lookupGetter__      a.__lookupSetter__      a.__proto__             a.constructor
a.hasOwnProperty        a.isPrototypeOf         a.propertyIsEnumerable  a.toLocaleString        a.toString              a.valueOf

a.BYTES_PER_ELEMENT     a.buffer                a.byteLength            a.byteOffset            a.copyWithin            a.entries
a.every                 a.fill                  a.filter                a.find                  a.findIndex             a.forEach
a.indexOf               a.join                  a.keys                  a.lastIndexOf           a.length                a.map
a.reduce                a.reduceRight           a.reverse               a.set                   a.slice                 a.some
a.sort                  a.subarray              a.values

> a.
>a=新的Uint8Array([1,2,3])
UINT8数组{0':1,'1':2,'2':3}
>a。
a、 定义设置器、定义设置器、查找获取器、查找设置器、原型构造函数
a、 hasOwnProperty a.isPrototypeOf a.Property可枚举a.ToLocalString a.toString a.valueOf
a、 每个元素的字节数a.buffer a.byteLength a.byteOffset a.copy in a.entries
a、 每个a.fill a.filter a.find a.find索引a.forEach
a、 索引a.join a.keys a.lastIndexOf a.length a.map
a、 减少,缩小,缩小,缩小,缩小,缩小,缩小,缩小,缩小,缩小,缩小
a、 排序a.子数组a.值
>a。

在控制台上编写要比在python上编写更长的时间才能获得等效的功能

> a = new Uint8Array([1, 2, 3])
Object.getOwnPropertyNames(a)
[ '0', '1', '2' ]
> //get the properties of Object Type
> Object.getOwnPropertyNames(Object.getPrototypeOf(a))
[ 'constructor', 'BYTES_PER_ELEMENT' ]
> //get the properties of parent
> Object.getOwnPropertyNames(Object.getPrototypeOf(Object.getPrototypeOf(a)))
[ 'constructor', 'buffer', ...]

您可以编写一个递归函数来获取所有内容(如果您不想使用
a.[TAB]


还有什么方法可以从REPL获取函数文档吗?在Ubuntu中,我必须在
>a之后按TAB两次
没有参数的
dir()
怎么样,例如
locals()
globals()
?好的,在REPL中按TAB两次会做很多有趣的事情(也是在空提示下)。当然,这是在交互工作时,但是
dir()
也不是一个真正的编程实用程序。
> a = new Uint8Array([1, 2, 3])
Uint8Array { '0': 1, '1': 2, '2': 3 }
> a. <<TAB>>
a.__defineGetter__      a.__defineSetter__      a.__lookupGetter__      a.__lookupSetter__      a.__proto__             a.constructor
a.hasOwnProperty        a.isPrototypeOf         a.propertyIsEnumerable  a.toLocaleString        a.toString              a.valueOf

a.BYTES_PER_ELEMENT     a.buffer                a.byteLength            a.byteOffset            a.copyWithin            a.entries
a.every                 a.fill                  a.filter                a.find                  a.findIndex             a.forEach
a.indexOf               a.join                  a.keys                  a.lastIndexOf           a.length                a.map
a.reduce                a.reduceRight           a.reverse               a.set                   a.slice                 a.some
a.sort                  a.subarray              a.values

> a.
> a = new Uint8Array([1, 2, 3])
Object.getOwnPropertyNames(a)
[ '0', '1', '2' ]
> //get the properties of Object Type
> Object.getOwnPropertyNames(Object.getPrototypeOf(a))
[ 'constructor', 'BYTES_PER_ELEMENT' ]
> //get the properties of parent
> Object.getOwnPropertyNames(Object.getPrototypeOf(Object.getPrototypeOf(a)))
[ 'constructor', 'buffer', ...]
function dir(obj, props) {
    if(typeof(props) === "undefined") { props = [];}
    //get parent object
    var pobj = Object.getPrototypeOf(obj);
    if(pobj) { 
        props = props.concat(Object.getOwnPropertyNames(pobj));
        return dir( pobj, props ) 
    }
    else 
    {
       return props.sort()
    }
}

> dir(a)
[ 'BYTES_PER_ELEMENT',
  '__defineGetter__',
  '__defineSetter__',
  '__lookupGetter__',
  '__lookupSetter__',
  '__proto__',
  'buffer', ...]