(注:我也在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代码都会运行,但是与div.my_target交互的LiveScript代码将在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>
...有这样的事吗?
发布于 2015-05-28 07:36:26
最好将.ls文件编译为.js,并在.html页面中引用JavaScript文件。
lsc livescript编译器有一些选项可以帮助实现这一点,例如watch(w)参数与compile(c)参数相结合,运行lsc -wc .时,运行lsc -wc .将监视当前目录中及下面的所有.ls文件,并在进行更改时编译它们。
例如,src/index.ls将编译为src/index.js。
我不认为使用LiveScript内联的特性很快就会被支持。
https://stackoverflow.com/questions/30338113
复制相似问题