Tag: coffeescript

无法在nodejs上运行coffeescript应用程序。 接收exception

我已经开始学习coffescript,并尝试着简单的啧啧。 但是,当我尝试使用coffee app.coffee命令运行我的app.coffee文件时,我一直得到这个exception; PS C:\Users\Office\Workspace\node\blog-demo\coffeepress> coffee .\app.coffee Error: In .\app.coffee, Parse error on line 1: Unexpected ' ' at Object.parseError (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:477 :11) at Object.parse (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:554:22) at exports.compile.compile (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee- script.js:43:20) at Object.exports.run (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-scrip t.js:79:34) at compileScript (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\command.js:175:29 ) at fs.stat.notSources.(anonymous function) (C:\Users\Rishav\AppData\Roaming\npm\node_modules\coffee-script\lib\coffe e-script\command.js:150:18) at fs.readFile (fs.js:176:14) at Object.oncomplete (fs.js:297:15) 咖啡代码是; ### Module dependencies. ### express = […]

将数据注入asynchronouscallback(使用node.js)

我正试图围绕如何使asynchronous编程工作。 在我目前的使用情况下,我有可能被调用的函数每秒多次,他们有callback,依靠多个variables之间可能会改变。 一个简单的例子:(为了简洁起见,使用coffeescript) doSomething = (requestor, thing, action, callback) -> thing.takeAction action, (result) -> # actually a lot of times this nests down even further requestor.report result callback result 如果在thing.takeAction返回其结果之前doSomething被多次调用不同的数据, 我认为我不能依赖于请求者和callback仍然是我需要它们的相同的东西。 正确? 为了避免这种情况,我需要以某种方式将请求者和callback注入takeAction的callback函数。 这有可能吗? 我有这样的想法 doSomething = (requestor, thing, action, callback) -> thing.takeAction action, (result, _requestor = requestor, _callback = callback) -> _requestor.report result _callback […]

JavaScript原型不复制

出于某种原因,我用CoffeeScript编写的类不会复制原型。 以下是我正在使用的确切代码: module.exports = class ListQueue constructor: -> @queue = [] @queueIds =[] @currentId = 0 # Adds the given element to the queue. # Returns the index of the element. add: (el) -> @queueIds.push @currentId @queue.push el @currentId++ # return @lastIndex, then increment shift: -> @queueIndexes.shift() @queue.shift() # Returns the index in the @queue […]

没有CoffeeScript的TowerJS?

我只是在看Node.js web开发的可能性。 我习惯于在ASP.NET MVC 3中进行编码,所以TowerJS和Geddy看上去对我来说很友善和熟悉(因为MVC模式) 然而,我不太喜欢CoffeeScript(因为它的奇怪的语法和debugging问题),所以我会很高兴,如果我可以使用Tower而不使用CoffeeScript – 而且如果我可以使用简单的JavaScript代替。 可能吗? 如果我去他们的网站,我到处都可以看到CoffeeScripts … (我会很高兴,如果我也可以使用另一个模板引擎(因为CoffeeKup也使用CoffeeScript),我将其更改为更像Razor的引擎 。

如何获取mongoose模型的单个属性?

在阅读The Little MongoDB的书后,我刚刚开始玩mongoose。 我很新,到目前为止,我已经知道如何从mongoose中查询我的集合,并根据它们的属性来查找文档,但是我想知道的是实际上如何仅显示文档中的每个文档的一个属性收集,例如,在一个Express res.send()。 就像一个学习实验一样,如果你愿意的话。 我在CoffeeScript中编写了这段代码: express = require 'express' app = express() http = require 'http' server = http.createServer app mongoose = require 'mongoose' mongoose.connect 'localhost', 'linkreferrers' # ## Ignore these configurations for now # app.configure -> # app.set 'views', __dirname + '/views' # app.set 'view engine', 'jade' linkSchema = new mongoose.Schema { […]

设置和访问asynchronous函数中的全局对象

这样的代码: fileArray = ['a.json','b.json','c.json'] dict = {} fileArray.map (f) -> fs.readFile f, (err, data) -> json.parse data, (k, v) -> dict[k] = v 我想写dict对象到一个文件。 我如何等待所有的asynchronousfunction完成? 或者还有什么其他的办法来做到这一点?

CoffeeScript – 如何避免不必要的回报?

这是我的CoffeeScript代码: http.createServer((req, res) -> if req.method is "POST" req.on "data", (data) -> queryData += data req.on "end", -> _.process req.url.substring(1), queryData, (response) -> res.writeHead 200, "Content-Type": "text/plain; charset=utf-8" fs.appendFile "./log", log, (err) -> if err console.log err else res.end response else res.writeHead 405, "Content-Type": "text/plain" res.end() ).listen 55385, "127.0.0.1" 以下是我正在编译的内容: http.createServer(function(req, res) { if (req.method […]

咖啡+ Express:意想不到的,

我正在学习使用Coffeescript在Express.js上创build一个应用程序。 我上传了我的代码: https : //github.com/findjashua/contactlist 当我尝试运行该应用程序时,出现以下错误: app.coffee:11:24: error: unexpected , res.send 'Hello World' ^ 我不明白这个问题。 有任何想法吗?

JavaScript setInterval没有正确绑定到正确的闭包

问题 嗨,大家好,我是JavaScript新手,我来自Python和Java的面向对象的世界,这是我的免责声明。 下面有两个代码块,替代实现,一个是JavaScript,一个是Coffeescript。 我想在Meteor.js应用程序的服务器上运行它们。 我遇到的问题是当使用绑定方法“this.printSomething”作为我的callback调用函数“setInterval”时,一旦执行该callback,它会丢失范围与实例导致“this.bar”未定义! 任何人都可以向我解释为什么JavaScript或coffescript代码不工作? JavaScript实现 function Foo(bar) { this.bar = bar; this.start = function () { setInterval(this.printSomething, 3000); } this.printSomething = function() { console.log(this.bar); } } f = new Foo(5); f.start(); 咖啡的实施 class foo constructor: (bar) -> @bar = bar start: () -> Meteor.setInterval(@printSomething, 3000) printSomething: () -> console.log @bar x = new […]

SyntaxError:意外的POST_IF错误

options = { host : 'http://localhost:8080' port : 8080 path : '.frameset?__report=stock_report.rptdesign' } http.get(options , (res) -> console.log "Got response : " + res.statusCode res.on 'data' , (chunk) -> console.log "BODY : " + chunk ).on 'error' , (e) -> console.log "Got error : " + e.message 我想在nodejs中发送tomcat服务器的http请求。 但意外的POST_IF错误发生。 为什么?