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

how to get list of all attribute and method from an JSObjects in 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));
  };
};

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

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

但是我怎样才能得到所有 keys/methods/vars

的列表

喜欢

p1['attributes'] or p1['keys'] 

那会 return

[a,b]
js.context['Object'].callMethod('keys', [p1]);