如何从dart中的JSObjects获取所有属性和方法的列表

H.R*_*.R. 2 webview dart

假设您要使用以下JavaScript代码:

var Point = function(x, y) {
 this.x = x;
 this.y = y;
 this.distanceFrom = function(otherPoint) {
  return Math.sqrt(Math.pow(otherPoint.x - this.x, 2) +
    Math.pow(otherPoint.y - this.y, 2));
  };
};
Run Code Online (Sandbox Code Playgroud)

在Dart代码中,使用索引运算符([])来获取和设置属性:

var p1 = new JsObject(context['Point'], [5, 1]);
print(p1['x']); // Prints 5.
Run Code Online (Sandbox Code Playgroud)

但是如何获得所有键/方法/变量的列表

喜欢

p1['attributes'] or p1['keys'] 
Run Code Online (Sandbox Code Playgroud)

那会回来的

[a,b]
Run Code Online (Sandbox Code Playgroud)

Jus*_*ani 6

js.context['Object'].callMethod('keys', [p1]);
Run Code Online (Sandbox Code Playgroud)