Add methods to JS classes via Dart #30554
Labels
area-web-js
Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.
type-enhancement
A request for a change that isn't a bug
web-js-interop
Issues that impact all js interop
There's currently no way for (non-SDK) Dart code to modify a class's prototype, which makes it difficult to expose Dart-like APIs for JS classes without resorting to inefficient wrapper objects. For example, we might want to expose Node.js's
net.Server.close([callback])
method so it exposes a more Dart-y future API:dart:html
does this frequently, but the inability to do it outside the SDK means that user-defined JS wrappers can't provide APIs that are as usable as those in the SDK.I propose we add an
@OnPrototype([String jsName])
annotation to thejs
package that explicitly indicates that a method should be added to the class's prototype. For example:The text was updated successfully, but these errors were encountered: