In Javascript it's very easy to attach methods to objects, either directly or via the prototype chain. Many libraries that I use have this behaviour. An example would be AngularJS's $resource library where returned objects have some magic methods on them like .$save() and .$delete() which trigger requests to the server.
However, after using Clojure for a while, I've begun to like its methodology of passing data structures to functions to trigger behaviour and for my next JavaScript project I'm considering trying to write it in this style.
My question is, what are the pros and cons to each of these ways of programming?
What are the pros/cons to attaching methods directly to objects (and as a result, usually mutating the object in place) vs. passing the object as a pure data structure into a function which will return a new data structure after processing it.
I realise in AngularJS that to take advantage of the two way binding you generally need to use the first system, however it seems that a framework like React can take advantage of either mutating in place or working with new instances of objects.
function foo(){ }only becomeswindow.fooin global scope.