* @ngdoc function * @name angular.bind * @module ng * @kind 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 [part
(self, fn)
| 1380 | * @returns {function()} Function that wraps the `fn` with all the specified bindings. |
| 1381 | */ |
| 1382 | function bind(self, fn) { |
| 1383 | var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : []; |
| 1384 | if (isFunction(fn) && !(fn instanceof RegExp)) { |
| 1385 | return curryArgs.length |
| 1386 | ? function() { |
| 1387 | return arguments.length |
| 1388 | ? fn.apply(self, concat(curryArgs, arguments, 0)) |
| 1389 | : fn.apply(self, curryArgs); |
| 1390 | } |
| 1391 | : function() { |
| 1392 | return arguments.length |
| 1393 | ? fn.apply(self, arguments) |
| 1394 | : fn.call(self); |
| 1395 | }; |
| 1396 | } else { |
| 1397 | // In IE, native methods are not functions so they cannot be bound (note: they don't need to be). |
| 1398 | return fn; |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | |
| 1403 | function toJsonReplacer(key, value) { |
no test coverage detected