Skip to content

Commit

Permalink
improve fn.bind polyfill formatting. fix linting error.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Jun 7, 2012
1 parent d5aae95 commit 6e26918
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,49 +229,33 @@ window.Modernizr = (function( window, document, undefined ) {
};
}

// TODO :: Add function proto bind
// Taken from ES5-shim https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
// ES-5 15.3.4.5
// http://es5.github.com/#x15.3.4.5
// Adapted from ES5-shim https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
// es5.github.com/#x15.3.4.5

if (!Function.prototype.bind) {
Function.prototype.bind = function bind(that) {

var target = this;
if (typeof target != "function") throw new TypeError();

if (typeof target != "function") {
throw new TypeError();
}

var args = slice.call(arguments, 1),
bound = function () {

if (this instanceof bound) {
var
args = slice.call(arguments, 1),
bound = function () {

var F = function(){};
F.prototype = target.prototype;
var self = new F;
if (this instanceof bound) {

var result = target.apply(
self,
args.concat(slice.call(arguments))
);
if (Object(result) === result) {
return result;
}
return self;
var F = function(){};
F.prototype = target.prototype;
var self = new F();
var result = target.apply(self, args.concat(slice.call(arguments)));

} else {

return target.apply(
that,
args.concat(slice.call(arguments))
);

}
if (Object(result) === result) return result;
return self;

} else {
return target.apply( that, args.concat(slice.call(arguments)));
}
};

return bound;
};
}
Expand Down

0 comments on commit 6e26918

Please sign in to comment.