Creating chaining methods in node.js?

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

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

That is non-blocking.

+5
source share
2 answers

You basically want to abstract the asynchronous nature of file processing operations in your API.

This can be done, I would recommend you take a look at the following article:

The article is written by Dustin Diaz, who is currently working on the @ everywhere JavaScript API , and it does exactly what you want, using a simple Queue implementation, you can create a free interface that is independent of any callback.

, API, .

+8

, JavaScript, , .

( ).

var File = new (function() 
{ 
  this.create = function(str) 
  { 
    return this; 
  } 
  this.rename = function(str) 
  { 
    return this; 
  } 
})(); 
0

All Articles