melanke / Watch.JS

watch the changes of any object or attribute

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unwatch function mustn't be anonymous

misterpah opened this issue · comments

hi there..
i found out watch work as expected if the function is anonymous.
watch(central.filesystem,function(){console.log("fileactive changed!")})

but it can't be unwatched if the function is anonymous.
unwatch(central.filesystem,function(){console.log("fileactive changed!")})

That's because in your unwatch call a new function is created, is not the original watcher.
To make it work, store the anonymous function in a variable and pass it to the unwatch, example:

Watch:

var watcher = function(){console.log("fileactive changed!")};
watch(central.filesystem,watcher);

Unwatch:

unwatch(central.filesystem,watcher)

thanks.

ps : great library btw 👍