* @ngdoc function * @name angular.bind * @function * * @description * Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for * `fn`). You can supply optional `args` that are prebound to the function. This feature is also * known as [function currying](http
(self, fn)
| 709 | * @returns {function()} Function that wraps the `fn` with all the specified bindings. |
| 710 | */ |
| 711 | function bind(self, fn) { |
| 712 | var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : []; |
| 713 | if (isFunction(fn) && !(fn instanceof RegExp)) { |
| 714 | return curryArgs.length |
| 715 | ? function() { |
| 716 | return arguments.length |
| 717 | ? fn.apply(self, curryArgs.concat(slice.call(arguments, 0))) |
| 718 | : fn.apply(self, curryArgs); |
| 719 | } |
| 720 | : function() { |
| 721 | return arguments.length |
| 722 | ? fn.apply(self, arguments) |
| 723 | : fn.call(self); |
| 724 | }; |
| 725 | } else { |
| 726 | // in IE, native methods are not functions so they cannot be bound (note: they don't need to be) |
| 727 | return fn; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | |
| 732 | function toJsonReplacer(key, value) { |
no test coverage detected