Utilities to access JavaScript from Dart.
o[prop]
.o[prop] = value
.These utilities are of great help if a JavaScript API takes a JavaScript object with keys that are not fixed because js package does not let you create a JavaScript object without declaring a Dart class with @JS()
and @anonymous
.
Include js_util.js
in index.html to use js_util functions.
<html> <head> <script async src="packages/js_util/dist/js_util.js"></script> <script async src="packages/browser/dart.js"></script> </head> </html>
A simple usage example:
final obj = newObject(); defineProperty(obj, 'foo', new PropertyDescription(enumerable: true, value: 1)); defineProperty(obj, 'bar', new PropertyDescription(enumerable: false, value: 2));
final obj = newObject(); setValue(obj, 'foo', 1); setValue(obj, 'bar', 2); print(getValue(obj, 'foo')); // 1 print(getValue(obj, 'bar')); // 2
final jsObj = toJS({ 'people': [ {'firstName': 'Kwang Yul', 'lastName': 'Seo'}, {'firstName': 'DoHyung', 'lastName': 'Kim'}, {'firstName': 'Kyusun', 'lastName': 'Kim'} ] }); final people = getValue(jsObj, 'people'); print(getValue(people[0], 'firstName')); // 'Kwang Yul'
Please file feature requests and bugs at the issue tracker.