* @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)
| 1370 | * @returns {function()} Function that wraps the `fn` with all the specified bindings. |
| 1371 | */ |
| 1372 | function bind(self, fn) { |
| 1373 | var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : []; |
| 1374 | if (isFunction(fn) && !(fn instanceof RegExp)) { |
| 1375 | return curryArgs.length |
| 1376 | ? function() { |
| 1377 | return arguments.length |
| 1378 | ? fn.apply(self, concat(curryArgs, arguments, 0)) |
| 1379 | : fn.apply(self, curryArgs); |
| 1380 | } |
| 1381 | : function() { |
| 1382 | return arguments.length |
| 1383 | ? fn.apply(self, arguments) |
| 1384 | : fn.call(self); |
| 1385 | }; |
| 1386 | } else { |
| 1387 | // In IE, native methods are not functions so they cannot be bound (note: they don't need to be). |
| 1388 | return fn; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | |
| 1393 | function toJsonReplacer(key, value) { |
no test coverage detected