Browse files

simplified core.bind() a bit

  • Loading branch information...
1 parent 9132d13 commit ac5742b1428dd84efb01c5ccdec6d8671897112b Ondrej Brinkel committed Feb 28, 2014
Showing with 7 additions and 11 deletions.
  1. +7 −11 lib/core.js
View
18 lib/core.js
@@ -107,18 +107,14 @@ var core = new (function () {
this.bind = function(self, fn)
{
var curryArgs = arguments.length > 2 ? Array.prototype.slice.call(arguments, 2) : [];
- if (typeof fn === 'function' && !(fn instanceof RegExp)) {
- return curryArgs.length
- ? function () {
- return arguments.length
- ? fn.apply(self, curryArgs.concat(slice.call(arguments, 0)))
- : fn.apply(self, curryArgs);
+
+ if (typeof fn === 'function') {
+ if (typeof Function.bind === 'function') {
+ return fn.bind.apply(self, curryArgs);
+ }
+ else {
+ return fn.apply(self, curryArgs);
}
- : function () {
- return arguments.length
- ? fn.apply(self, arguments)
- : fn.call(self);
- };
} else {
// in IE, native methods are not functions so they cannot be bound (note: they don't need to be)
return fn;

0 comments on commit ac5742b

Please sign in to comment.