2017-03-17 19 views
1

我使用节点猎犬作为目录观察者。在节点猎犬中绑定多个事件?

hound = require('hound'); 
 

 
watcher = hound.watch('/dir'); 
 

 
watcher.on('create', function(file) { 
 
    console.log('hello'); 
 
}); 
 
watcher.on('change', function(file) { 
 
    console.log('hello'); 
 
});

我怎样才能绑定createchange事件假设回调函数将执行完全相同的任务一起?那可能吗?

回答

0

只是声明只有一个单一的功能,并传递到两个on电话:

const hound = require('hound'); 

function hello(file) { 
    console.log('hello'); 
} 
const watcher = hound.watch('/dir'); 
watcher.on('create', hello); 
watcher.on('change', hello);