Tag: coffeescript

创build单节点模块以访问在coffeescript中创build的单独文件中的多个扩展类

我想创build一个包含多个类的单个节点库,每个类都使用另一个文件中的coffee-script创build并相互扩展。 例如,说我在node_modules / mymodule / src中有以下文件: 文件1: class Base constructor: (@foo) -> module.exports = Base 文件2: Base = require './Base.coffee' class Derived extends Base constructor: (@bar) -> super module.exports = Derived 文件3: Base = require './Base.coffee' class Derived2 extends Base constructor: (@baz) -> super module.exports = Derived2 有没有办法以这种方式绑定这三个类,以便我可以在package.json文件中定义“mymodule”,然后像这样访问模块及其类? 使用mymodule的文件: my module = require 'mymodule' Base […]

Javascript和承诺与Q – 封闭的承诺问题

我使用Node.js和Q编写服务器端的asynchronous代码。 我对诺言是新的(对于asynchronous编程我一般都是新手),而且我遇到了一些麻烦,我不能通过查看Q文档来解决这个问题。 这里是我的代码(这是coffeescript – 让我知道,如果你想看到的JavaScript): templates = {} promises = [] for type in ['html', 'text'] promises.push Q.nfcall(fs.readFile , "./email_templates/#{type}.ejs" , 'utf8' ).then (data)-> # the problem is right here – by the time # this function is called, we are done # iterating through the loop, and the value # of type is incorrect […]

为什么这个CoffeeScript比这个Ruby脚本更快?

我正在解决一个问题,要求我find所有在4,000,000以下的所有偶数斐波那契数的总和,我注意到下面的CoffeeScript执行得比下面的Ruby快。 CoffeeScript的 sum = 0 f = (n) -> if n == 0 then return 0 else if n == 1 then return 1 else return f(n-1) + f(n-2) console.log "Starting…" for i in [1..4000000] ff = f(i) break if ff >= 4000000 sum += ff if ff % 2 == 0 console.log ".." + […]

返回发送给Hubot的原始消息

有没有办法返回Hubot听到/回复的原始信息? 试图访问message和@ message ,但似乎错误时被调用。 寻找像这样的东西: robot.respond /test/, (msg) -> msg.send msg.the_message_that_the_user_typed_in 在这个例子中,它会回显用户input的全部文本。 实际上,我会玩文本和剥离一些东西,但我想要一个原始文本的准确副本搞乱。

CoffeeScript代码覆盖

是否可以在不使用CoffeeScriptRedux编译器(在ibrik中使用这个编译器)的情况下对CofeeScript源执行代码覆盖。 我理解这个新编译器的优点,但看起来还没有完成,不适合我的项目。

如何检查请求是否在Total.js控制器中发布数据

我想要一个解决scheme,通过validation用户是否提供了一些数据来保持相同function的查看和发布操作。 我的total.js控制器是这样的 # framework exports.install = (framework) -> framework.route "/subscribe", subscribe framework.route "/subscribe", subscribe, ['post'] # subscribe form and action subscribe = -> self = this post = self.post if post Subscriber = self.model('subscriber') Subscriber.save post self.view "form" 问题是,当我只查看页面(不提交数据)时, post是{} ,所以它总是input。 如果我比较{} ( if post isnt {} self.post if post isnt {} )条件总是为false,可能是因为self.post不是一个空对象。 [更新] 查看页面时: […]

为什么在callback函数setInterval中取消蓝鸟承诺?

Promise = require 'bluebird' cb = -> console.log 'callback!' p = Promise.resolve(5) .cancellable() .tap -> p.cancel() setInterval(cb, 100) cb函数只能被调用一次。 注释.tap -> p.cancel()允许它重复运行。 添加一个try块没有帮助。 也许这是显而易见的,但我做了一些研究,找不到解释。

coffeescript传递require()参数错误

代码require ('./routes') app编译require('./routes'(app)); 但我需要它来编译require('./routes)(app) 。 我怎么能这样做?

将SVGpath转换为线段

我正在尝试将SVGpath转换为Node中的点列表。 我使用elementtree来parsingSVG文件。 d是path的定义,getPos简单地将“x,y”转换为带有x和ay的对象,doLine只是简单地将该坐标添加到列表中。 d = path.get('d') words = d.split(' ') oldPos = undefined startPos = undefined for i in [0..words.length] word = words[i] if word == 'm' or word == 'M' oldPos = getPos(words[i + 1]) startPos = getPos(words[i + 1]) i += 1 else if word == 'l' or word == 'L' console.log('done nothing…') […]

从anom访问实例variables。 function在咖啡脚本

我试图从anom函数访问@cols,即使它被定义,它仍然是未定义的(在第二行)。 csv = require'csv' class级库存 构造函数:(@file) – > @cols = {} #读取文件并推送到cols CSV()。 fromPath(@文件,列:true)。 在'数据'上,(d,索引) – > #推到cols console.log @cols inventory = new Inventory(__ dirname +'/sample.csv')