Using dart to create a javascript library

早过忘川 提交于 2019-12-01 06:07:02
Günter Zöchbauer

Even though Dart supports this use case, if you target JavaScript developers I would stick with JavaScript.

@AlexandreArdhuin shows in his answer to Expose Dart functions to javascript how you can make a Dart function available to JavaScript.
Under the are many examples how to do function calls and pass data between Dart and JavaScript.

kao peter

Wrap dart class into custom element, the Dart object auto expose to javascript. Assume we have 2 Dart Classes, SlickGrid Class contains Column class in Dart

class SlickGrid{
   List<Column> columns;
}

class Column{}

class GridWrap extends HtmlElement {
      ShadowRoot shadowRoot;
      SlickGrid grid;  // here is your cool object
}

compile to javascript, and register custom element, then open javascript console,

//this is SlickGrid object
var grid= document.querySelector('cj-grid').grid; 
// this is dart Column Object
var column = grid.columns.$index(0,0);  
// call toString function in dart object that produce json string...
column.toString$0()  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!