瀏覽代碼

[js] Add `Lib.dynamicImport()` method (#10465)

* [js] Add `Lib.dynamicImport()` method

* [js] Fixed the return type of `Lib.dynamicImport()` method
Cédric Belin 3 年之前
父節點
當前提交
ec4a73dc81
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      std/js/Lib.hx

+ 8 - 0
std/js/Lib.hx

@@ -34,6 +34,14 @@ class Lib {
 		js.Syntax.code("debugger");
 	}
 
+	/**
+		Inserts an `import` expression that loads JavaScript object from
+		a module or file specified in the `module` argument.
+	**/
+	public static inline function dynamicImport(module:String):js.lib.Promise<Dynamic> {
+		return js.Syntax.code("import({0})", module);
+	}
+
 	/**
 		Display an alert message box containing the given message.
 		@deprecated Use Browser.alert() instead.