2020年3月25日 星期三

從 dart 呼叫 javascript


參考官網文章:  http://dartdoc.takyam.com/articles/js-dart-interop/


// index.html

<html><head><meta charset='utf-8'></head><body>
    <script type='application/javascript' src='hello.js'></script>
    <script type='application/javascript' src='main.js'></script>
</body></html>

// hello.js
var greeting="Hello"; // 1. variable

function fun( ){ //2. function
    console.log("How are you?");
}

class Rectangle {
    constructor(width, height) {
      this.width = width;
      this.height = height;
    }
}
function rectangle(width, height) { // 3. object
  return new Rectangle(width, height); // return an object
}

// main.dart
import 'dart:js';
void main() { 

  var greeting = context['greeting']; // 1.
  print("$greeting");

  context.callMethod('fun'); //2.

  final rectangle = JsObject(context['rectangle'], [5, 1]); //3.
  print(rectangle['width']);
}

沒有留言:

張貼留言

使用 pcie 轉接器連接 nvme SSD

之前 AM4 主機板使用 pcie ssd, 但主機板故障了沒辦法上網, 只好翻出以前買的 FM2 舊主機板, 想辦法讓老主機復活, 但舊主機板沒有 nvme 的界面, 因此上網買了 pcie 轉接器用來連接 nvme ssd, 遺憾的是 grub2 bootloader 無法識...