Tag: coffeescript

如何在node.js中logging每个方法调用,而无需在每个地方添加debugging行?

我想logging发出请求的用户的user_id,以及为JavaScript类调用的每个方法的方法名称。 例如: 35 – log_in 35 – list_of_other_users 78 – log_in 35 – send_message_to_user 35 – connect_to_redis 78 – list_of_other_users 因为一切都是asynchronous用户35和78可能在同一时间做的东西。 所以我想确保每个日志行以user_id开头,这样我就可以grep了,而且一次只能看到一个用户的活动。 有没有一个超级聪明的方式来做到这一点,而不是每个方法都添加logging器语句?

与coffeescript jsx的Jest?

如何使用Jesttesting用CoffeeScript + React jsx编写的React组件? Jest提供的唯一的CoffeeScript示例使用普通的CoffeeScript,并且不能与CoffeeScript + React JSX一起工作(语法错误达到< )。 我曾经尝试过 第一次尝试:execSync // preprocessor.js var execSync = require('exec-sync'); module.exports = { process: function (src, path) { return execSync('browserify -t coffee-reactify ' + path); } }; 这工作,但需要太多的时间(虚拟testing12秒)。 然后我试着: 第二次尝试:咖啡反应变换 // preprocessor.js var coffee = require('coffee-script'); var transform = require('coffee-react-transform'); module.exports = { process: function(src, path) { if […]

我可以在一个项目中混合使用JS和CoffeeScript吗?

我正在使用ExpressJS和app.js是直的JavaScript。 如果我想使用CoffeeScript,是否必须重写app.js,或者只能使用CoffeeScript编写其他文件?

如何正确处理与IcedCoffeeScript错误?

在node.js中,通常的做法是将错误消息作为第一个参数返回给callback函数。 在纯JS(Promise,Step,Seq等)中有很多解决这个问题的方法,但是没有一个能够与ICS集成。 什么是正确的解决scheme来处理错误,而不会失去太多的可读性? 例如: # makes code hard to read and encourage duplication await socket.get 'image id', defer err, id if err # … await Image.findById id, defer err, image if err # … await check_permissions user, image, defer err, permitted if err # … # will only handle the last error await socket.get 'image […]

CoffeeScript编译器API

我正在使用CoffeeScript(编写一个Cakefile)。 我想编译一些其他的CoffeeScript文件,la coffee -o lib -c src 我可以在subprocess中启动上述命令,但是这种方法存在跨平台的问题,使得error handling变得困难。 我宁愿使用一个API。 我很乐意使用command.coffee的确切函数,但是我无法解决这个问题。 附录:我看到require('coffee-script').compile ,编译一个string到另一个string。 这仍然让我做循环的文件和子文件夹和写输出的繁重的工作。

coffeescript版本的string.format,sprintf()等javascript或node.js

如何在coffeescript中string.format()或sprintf()?

在Mac 10.7.2上安装coffeescript时出错

节点和npm都安装并且是最新的,但是在尝试安装coffeescript时不断收到这个错误。 我还是新手编程,所以任何意见将不胜感激。 test-macbook:~ Test$ npm -v 1.1.0-3 test-macbook:~ Test$ node -v v0.6.8 test-macbook:~ Test$ npm install -g coffee-script npm http GET https://registry.npmjs.org/coffee-script npm http 304 https://registry.npmjs.org/coffee-script npm ERR! Could not create /usr/local/lib/node_modules/___coffee-script.npm npm ERR! error installing coffee-script@1.2.0 npm ERR! Error: EACCES, permission denied '/usr/local/lib/node_modules/___coffee-script.npm' npm ERR! npm ERR! Please try running this command again as […]

如何通过Mac上的terminal更新node.js和CoffeeScript版本?

我的系统node.js版本是v0.6.1,但是当前的稳定版本是v0.6.7。 我的系统CoffeeScript版本是v1.1.2,但是当前的稳定版本是v1.2.0 我怎么能通过mac上的terminal(使用mac)更新node.js和CoffeeScript? 我对命令行非常好,但是我需要一些帮助来开始更新这些应用程序。 非常感谢您的帮助。

用grunt运行2个asynchronous任务

我正在一个小型的节点项目上工作,我使用coffeescript和更less的客户端代码。 我正在尝试使用grunt设置我的开发环境。 我已经实现了像这样运行服务器的自定义grunt任务: start = require './start' #just a function to start express.js application grunt.registerTask 'server', 'Starting server', -> grunt.log.write 'Preparing server to start' done = do @async start (err) -> grunt.log.write "server running at localhost:4000" 我也想用grunt-contrib-watch插件运行“watch”任务: grunt.initConfig watch: coffee: files: ['public/coffee/**/*.coffee'] tasks: ['coffee'] jade: files: ['public/jade/**/*.jade'] tasks: ['jade'] less: files: ['public/less/**/*.less'] tasks: ['less'] 问题是:如何使这两个任务(手表和服务器)同时运行? […]

节点coffeescript类文件和inheritance

我有2个类文件: foo.coffee:class class Foo bar.coffee:class class Bar extends Foo 我如何定义这些类,使它们在全球范围内可用? 我得到Bar中的错误, Foo没有定义。 我有一个index.js文件,我调用node来运行脚本。 这里是index.js的内容,我很可能也做了这个错误: exports.Foo = require("./foo") exports.Bar = require("/bar")