2017-03-17 17 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);