angular/angular.js — pull request #3353 by dbinit (2013-07-25 22:10:19+00:00)
Title: feat($rootScope): add $bind method for wrapping functions in $apply block

This PR scratches an itch I've had for a while where I need to wrap a function with scope.$apply but don't want it to execute immediately.

Something like this:
```javascript
element.bind('click', function(event) {
return scope.$apply(function() {
// do something
});
});
```

gets simplified to:
```javascript
element.bind('click', scope.$bind(null, function(event) {
// do something
}));
```

Even better, if I'm working with a class I can go from this:
```javascript
var self = this;
element.bind('click', function(event) {
return scope.$apply(function() {
return self.someMethod(event);
});
});
```

to something like this:
```javascript
element.bind('click', scope.$bind(this, this.someMethod));
```

In addition to adding the new method, I've gone through the existing code and found places that would benefit from using it. I also added tests where removing the existing $apply didn't produce an error. That way I could be sure the new method is doing what it should.

Please let me know what you all think. I have everything split into separate commits to make review easier. Obviously I'd merge and add a nice commit message if accepted.