gpt4 book ai didi

dart - Web应用程序何时执行DART代码?

转载 作者:行者123 更新时间:2023-12-03 03:47:04 25 4
gpt4 key购买 nike

如果我有一个带有<script>的HTML文件,该文件链接到我的Dart程序,我的代码何时执行?具体来说,什么时候执行顶层分配,什么时候运行main()函数?

最佳答案

According to the dart documentation:

The Dart app must have a visible top-level function called main(). The browser invokes main() when the DOM content is loaded (but see caveat in the next section).



The caveat is:

The precise semantics of Dart execution on an HTML page are evolving and likely to change by the time Dart is natively supported in a production browser.

Currently, your Dart app’s main() function is run after DOM content is loaded, but the exact timing is undefined (e.g., with respect to the load event or deferred JavaScript). In the future, we may invoke main() synchronously during HTML parsing instead of waiting for DOM content to load.



根据此推文:

@caffinatedmonk top-level variables are lazily initialized. i.e. on their first access.

— Seth Ladd (@sethladd) March 10, 2014



变量在首次访问时被初始化。

关于dart - Web应用程序何时执行DART代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22277509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com