2

(注意:我也在https://github.com/gkz/LiveScript/issues/731上问过这个问题)

当我直接在 html 文件中使用 LiveScript 时,我无法在看到时立即运行 livescript 代码。例如;

...
<script src="livescript.js"></script>

<div class="my_target"></div>

<script type="text/ls">
# my livescript code will interact with div.my_target
</script>

<script>
/* a javascript code that will interact with div.my_target
</script>

<script type="text/ls">
# my livescript code does something else
</script>

<script>
    var LiveScript = require("LiveScript");
    LiveScript.go();
</script>

LiveScript 代码都将运行,但与之交互的 LiveScript 代码div.my_target在javascript 代码运行之后与其交互,而不是之前

如果我定义

<script>
    var LiveScript = require("LiveScript");
    LiveScript.go();
</script>

每次定义 LiveScript 代码后,所有 LiveScript 代码都会运行一次以上。

### livescript code 1
### LiveScript.go()
...
### livescript code 2
### LiveScript.go()
...
### livescript code 3
### LiveScript.go()
...

执行此代码时:

  • livescript code 1将运行 3 次,首先将在定义后立即运行
  • livescript code 2将运行 2 次,第一次将在定义后立即运行
  • livescript code 3将运行 1 次,这将在定义后立即运行

如果是这样,LiveScript将更容易在 html 中使用,并且会像 Web 开发的原生语言一样使用

...
<script src="livescript.js"></script>
<script>
    var LiveScript = require("LiveScript");
    LiveScript.doSomeMagic_Kaboooommm();
</script>

...
<script type="text/ls">
# my livescript code
</script>

... more html

<script type="text/ls">
# my livescript code
</script>

...

<script type="text/ls">
# my livescript code
</script>
...

有没有办法做到这一点?

4

1 回答 1

0

您最好编译.ls文件.js并引用页面中的 JavaScript 文件.html

livescript 编译器lsc有一些选项可以帮助解决这个问题,例如watch(w)参数与参数结合compile(c),runninglsc -wc .将监视.ls当前目录及以下目录中的所有文件,并在您进行更改时编译它们。

例如,src/index.ls将编译为src/index.js.

我认为使用 LiveScript 内联的功能不会很快得到支持。

于 2015-05-28T07:36:26.180 回答