嘿,我正在学习CoffeeScript而且我一直在犯错误.这是我的代码:
Db = require('./lib/mongodb').Db
ObjectID = require('./lib/mongodb').ObjectID
Server = require('./lib/mongodb').Server
class UserDataProvider
constructor = (host,port)->
this.db = new Db( 'test' , new Server(host ,port,{}))
getCollection = (callback) ->
this.db.collection 'data',(error,data)->
if error then callback(error)
else callback(data)
findAll = (callback) ->
this.getCollection (error,data)->
if error then callback error
else
data.find (error, cursor) ->
if error then callback error
else
cursor.toArray (error, results)->
if error then callback error
else callback(null,results)
findById = (id,callback)->
this.getCollection (error, data)->
if error then callback error
else …Run Code Online (Sandbox Code Playgroud) 我有一个src/templates/充满胡子模板的目录.我如何组合和缩小这些内容,以便它们可以在我的CoffeeScript应用程序中使用?
我已经在之后的方向https://github.com/jashkenas/coffee-script/wiki/%5BHowTo%5D-Compiling-and-Setting-Up-Build-Tools的组合和涅槃我CoffeeScript的SRC到JS.
不使用jQuery,我想知道如何模仿jQuery插件
例如,也许$('div.x').plugin()将一个onclick附加到div,并递增并显示内部值.
jQuery在哪里实际存储了内部变量的对象?
是否在某处显式创建了一个对象并与每个节点相关联?
我迷失了,试图向自己解释为什么在主应用程序列表中没有明确的对象创建....必须以某种方式在插件中发生?
(PS:我不太关心查询引擎方面......只是插件方:)
谢谢
将任何(等长)行数组转换为列数组的最优雅方法是什么?
例如:
[1,2,3]
[4,5,6]
# To
[1,4]
[2,5]
[3,6]
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止:
grid = [
[1,2,3]
[4,5,6]
]
grid2 = []
for i in grid[0]
grid2.push []
for row, y in grid
for el, x in row
grid2[x].push el
Run Code Online (Sandbox Code Playgroud)
有没有可能会做到1-liner?
所以我有一个Express.js服务器设置,但在生产约5分钟后 - http://balupton.com - 它崩溃并重新启动.
我的网站的源代码在这里:https://github.com/balupton/balupton.docpad/blob/master/server.coffee
它用于创建服务器的docpad参考位于:https: //github.com/bevry/docpad/blob/master/lib/docpad.coffee#L589
它托管在http://no.de上,这是每5分钟左右不断出现在日志中的内存不足异常:
FATAL ERROR: CALL_AND_RETRY_2 Allocation failed - process out of memory
[ Jul 7 14:02:13 Stopping because all processes in service exited. ]
[ Jul 7 14:02:13 Executing stop method (:kill). ]
[ Jul 7 14:02:13 Executing start method ("env `cat /home/node/node-service/profile` /opt/nodejs/latest/bin/node /home/node/node-service/releases/20110707135409/server.js &"). ]
[ Jul 7 14:02:13 Method "start" exited with status 0. ]
Express server listening on port 80 and directory … 就像是...
$('.foo').live 'click', ->
setTimeout (()->$(this).parent().hide()), 5000
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我在第21行有一个"太多"的问题"我无法将这个咖啡脚本代码编译成Node.js关于这些")"的任何帮助?谢谢
amqp = require('amqp')
class Queue
constructor: (ip = 'localhost') ->
@ip = ip
@receivedObject
@connection = amqp.createConnection({ host: @ip })
subscribeTaskQueue: (queueToSubscribe) ->
self = @
self.connection.on('ready', ->
q = self.connection.queue(queueToSubscribe)
q.bind('#')
q.subscribe({ ack: true }, (message) ->
self.receivedObject = message
console.log(self.receivedObject)
)
)
addTaskToQueue: (queue, objectToSend) ->
@connection.publish(queue, objectToSend)
module.exports = Queue
Run Code Online (Sandbox Code Playgroud) 我正在使用mongoose @ 2.0.4,我想mongoose.connect()在模块中整齐地抽象掉调用.
所以使用nodejs,我希望以下工作:
在myMongoose.coffee:
mongoose = require 'mongoose'
mongoose.connect 'mongodb://localhost/test'
@exports = mongoose
Run Code Online (Sandbox Code Playgroud)
并用于: MyModel.coffee
mongoose = require 'myMongoose'
console.log mongoose #Prints massive object (including Schema)
Schema = mongoose.Schema
console.log Schema # undefined
Run Code Online (Sandbox Code Playgroud)
为什么访问像Schema不起作用的子元素(技术上是构造函数,我认为)?即使添加@exports.Schema = mongoose.Schema到myMongoose.coffee也无法解决问题.
我正在编写第一个开源Backbone.js应用程序.存储库在这里https://github.com/defrag/Backbone-Invoices
我在为Invoice保存LineItems数组时遇到问题.好吧,只有在编辑后保存,因为它将当前编辑的发票中的行项目保存到localstorage中的所有发票.Dunno为什么会这样,他们总是有相同的Cids.创建发票时的默认订单项始终为cid0.有帮助吗?
class window.Invoice extends Backbone.Model
initialize: ->
defaults:
date: new Date
number: '000001'
seller_info: null
buyer_info: null
line_items: [new LineItem]
Run Code Online (Sandbox Code Playgroud)
我不明白的最后一件事是为什么骨干不能保存嵌套属性.正如您将在回购中看到的那样:
handleSubmit: (e) ->
data = {
date : @$("input[name='date']").val(),
number : @$("input[name='number']").val(),
buyer_info : @$("textarea[name='buyer_info']").val(),
seller_info : @$("textarea[name='seller_info']").val(),
line_items: @model.line_items.toJSON()
}
if @model.isNew()
invoices.create(data)
else
@model.save(data)
e.preventDefault()
e.stopPropagation()
$(@el).fadeOut 'fast', ->
window.location.hash = "#"
Run Code Online (Sandbox Code Playgroud)
事情是在编辑表单和更改行项目的值之后,它们不会在集合中更改.添加新的发票订单项集合工作.有帮助吗?:)我很难理解每个人的工作方式:)
你可以在这里查看:http://backbone-invoices.brillante.pl/
我是Coffeescript的新手,我在翻这个Javascript时遇到了麻烦:
Handlebars.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);
if (optionalValue) {
console.log("Value");
console.log("====================");
console.log(optionalValue);
}
});
Run Code Online (Sandbox Code Playgroud)
进入工作Coffeescript.我想,我想要的部分是如何将"debug"参数传递给registerHelper函数,还传入一个带有可选参数的匿名函数.
这个语法:
Handlebars.registerHelper: "debug", -> (optionalValue)
console.log("Current Context")
console.log("====================")
console.log(this)
if optionalValue
console.log("Value")
console.log("====================")
Run Code Online (Sandbox Code Playgroud)
不适合我.
coffeescript ×10
javascript ×6
node.js ×3
backbone.js ×1
express ×1
jquery ×1
minify ×1
mongoose ×1