在node.js中创建链式方法? [英] Create chained methods in node.js?

查看:116
本文介绍了在node.js中创建链式方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在node.js中创建这样异步的链式方法

Is it possible to create chained methods that are asynchronous like this in node.js

File.create('file.jpg').rename('renamed.jpg').append('Hello World')

那个就是说非阻塞。

推荐答案

你基本上想要抽象文件的异步性质处理您的API的操作。

You basically want to abstract the asynchronous nature of the file-handling operations on your API.

可以这样做,我建议您查看以下文章:

It can be done, I would recommend you to give a look to the following article:

  • Asynchronous method queue chaining in JavaScript

这篇文章是由Dustin Diaz撰写的,他现在正在 @ anywhere JavaScript API ,他完全按照您的意愿行事,使用简单的Queue实现,可以创建流畅的界面,独立于任何回调。

The article was written by Dustin Diaz, who currently works on the @anywhere JavaScript API, and he does exactly what you want, using a using a simple Queue implementation, a fluent interface can be created, being independent of any callback.

asynchronicity 是隐藏的,它由你的API内部处理,这是一个很好的简单技术。

The asynchronicity is hidden and it is handled internally by your API, it's a nice and simple technique.

这篇关于在node.js中创建链式方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆