I'm new to JS and i'm Currently reading 'this & Object Prototypes' of the greate 'You Don't Know JS' book series. In Chapter 2 (Softening Binding):
if (!Function.prototype.softBind) {
Function.prototype.softBind = function(obj) {
var fn = this,
curried = [].slice.call( arguments, 1 ),
bound = function bound() {
return fn.apply(
(!this ||
(typeof window !== "undefined" &&
this === window) ||
(typeof global !== "undefined" &&
this === global)
) ? obj : this,
curried.concat.apply( curried, arguments )
);
};
bound.prototype = Object.create( fn.prototype );
return bound;
};
}
(!this || (typeof window !== "undefined" && this === window) || (typeof global !== "undefined" && this === global)
Thanks