问题标签 [livescript]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
858 浏览

javascript - 从 LiveScript 模块导出函数的最佳方法是什么?

使用 LiveScript,当您在文件中编写一些代码时,默认编译器会将编译后的代码包装在一个匿名函数中:

编译这个:

给出了:

没关系!但我想为我的模块导出一些 API 函数,所以我现在要做的是:

给出:

我在浏览器上下文中工作,我想知道是否没有更好的解决方案。它确实有效,但我更喜欢这样的事情:

它的代码更少(在这样一个小例子中没有太大的区别)。

0 投票
2 回答
523 浏览

coffeescript - 浏览咖啡脚本和 livescript 文件的混合

我有一个主要的咖啡文件以及其他咖啡和 livescript 文件的混合。

我可以跑

但试图运行

给出一个错误:

我看到的唯一解决方法是先将 ls 文件编译为 js。有没有更简单直接的方法来混合 ls 和咖啡文件?

0 投票
1 回答
540 浏览

javascript - LiveScript - 当有多个回调时如何使用回呼运算符?

例如:

是否可以在两个回调上应用回呼运算符?

0 投票
2 回答
1938 浏览

angularjs - How to pass yeoman prompt options through to templated files?

I'm writing a version of generator-angular with extra options to support sources in livescript, and bootstrap with less, font-awesome etc. Work in progress is at https://github.com/gmp26/generator-angular-ls

I'm hung up on a trivial wish. I'd like the initial 'Halo 'Halo installed list to reflect the options installed in response to yeoman questions rather than be a constant common denominator list.

As a first attempt - I tried lodash templates in templates/*/spec/controller.(ls|js|coffee) to adjust the $scope.awesomeThings list which is defined in those files. This fails because my optional flags defined by prompt (this.bootstrap, this.lessBootstrap, this.fontAwesome) in a similar manner to generator-angular's this.bootstrap and this.compassBootstrap are not available in the 'this' context where the template is called. Both 'this' contexts are Generators but I believe the prompting 'this' context is the generator angular:app whereas the template is called in angular:controller.

So, any ideas how to communicate a flag from the app/index.js prompting phase through to the templating phase?

I feel there should be a way to do this that does not involve writing and reading files in the generated app folder.

Maybe this is what the hookFor calls are for?

0 投票
1 回答
189 浏览

livescript - LiveScript 类范围这个自我 jquery 问题

在我的 jQuery 函数中,我实际上需要两个范围,所以我不能只更改匿名函数的绑定方式。我可以放在 method2 的开头,self = @然后使用self.method. 我想一直使用self.method. 但我宁愿不要把它放在每个函数的开头。

无论如何要self在构造函数中设置始终存在并指向@?我尝试的一切都失败了。self在方法中始终未定义。

我把 Coffeescript 作为一个标签,因为它与 LiveScript 非常相似。

0 投票
1 回答
203 浏览

livescript - LiveScript 关闭不工作

为什么这会编译为

a未传入,因此未定义。我做错了自我执行关闭吗?

0 投票
1 回答
273 浏览

javascript - 接收器上的单子模式

当我在阅读了几十篇教程后了解了 monad 时,我正在尝试在 JavaScript 中实现该模式。我正在使用LiveScriptPrelude来翻译一些 Haskell monad 示例。

所以我试图作为练习实现的 monad 是 List monad。我在 LiveScript 中写了以下内容:

将函数嵌套在同一缩进级别的 LiveScript 语法非常方便,但它显然会转化为 JavaScript 回调地狱:

我想要的是在接收器上实现模式以便能够像这样使用它:

在观看了 Crockford 用 Ja​​vaScript(代码)解释 monad 的视频后,我了解到他提出的只是一个对象,其方法也可以用原型实现。该方法是构造函数,是一个实例方法,它使用给定的参数对值运行函数。然后向原型添加一个新方法,该方法在单值上运行给定函数。MONADunitbindlift

但是,它是真正的单子还是像 jQuery 这样的单子模式?我对 monad 的这种特殊解释有疑问,因为没有计算序列,该bind方法立即运行函数并返回“monad”的新实例,它不是组合,就像我在 LiveScript 中实现的基于关于 Haskell 的例子。

所以我的问题是:

  1. 我对 monad 的实现是否正确?
  2. Crockford对 monad 的实现是否正确?
0 投票
1 回答
275 浏览

javascript - Livescript 的克隆运算符 ^^ 在服务器端(node.js)不起作用

livescript中,我们可以使用^^来克隆一个对象。

例如,

将被编译为

但是,这些代码在浏览器中可以成功运行,但在 node.js 中却不行。

  • fun {a: 1}在浏览器中,它在控制台中打印。
  • 在 node.js 中,它什么也没显示。

什么原因?

0 投票
2 回答
582 浏览

javascript - 带有 Meteor.js 的 LiveScript

我想知道是否有一种简单的方法可以在 Meteor.js 应用程序中将 LiveScript 文件编译为 js。找到这个 mrt 扩展:

https://atmosphere.meteor.com/package/livescript-latest

但这样做mrt add livescript-latest只会给出错误:

在此扩展的 git 存储库中,该错误已修复。所以我可以直接把这个放到smart.json:

这似乎安装得很好,但是当我尝试将 .ls 文件添加到项目时,它们似乎没有被编译。

还有其他人尝试使用 Meteor.js 应用程序进行 LiveScripting 吗?

0 投票
1 回答
231 浏览

coffeescript - CoffeeScript / LiveScript 和数据构造函数

我对 SML 的经验很少。现在我想学习 LiveScript,但我被数据类型困住了。那么,是否可以使用 SML / Haskell / OCaml 等数据构造函数来创建类型?如果不是,创建数据类型的首选方法是什么?