* @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)
| 1246 | * @returns {function()} Function that wraps the `fn` with all the specified bindings. |
| 1247 | */ |
| 1248 | function bind(self, fn) { |
| 1249 | var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : []; |
| 1250 | if (isFunction(fn) && !(fn instanceof RegExp)) { |
| 1251 | return curryArgs.length |
| 1252 | ? function() { |
| 1253 | return arguments.length |
| 1254 | ? fn.apply(self, concat(curryArgs, arguments, 0)) |
| 1255 | : fn.apply(self, curryArgs); |
| 1256 | } |
| 1257 | : function() { |
| 1258 | return arguments.length |
| 1259 | ? fn.apply(self, arguments) |
| 1260 | : fn.call(self); |
| 1261 | }; |
| 1262 | } else { |
| 1263 | // In IE, native methods are not functions so they cannot be bound (note: they don't need to be). |
| 1264 | return fn; |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | function toJsonReplacer(key, value) { |
no test coverage detected