function b_i_n_d(that) { var target = this; if (typeof target !== 'function') { throw new Error('Error, you must bind a function.'); } var args = Array.prototype.slice.call(arguments, 1); // for normal call var bound = function () { if (this instanceof bound) { var F = function(){}; F.prototype = target.prototype; var self = new F(); var result = target.apply( self, args.concat(Array.prototype.slice.call(arguments)) ); if (Object(result) === result) { return result; } return self; } else { return target.apply( that, args.concat(Array.prototype.slice.call(arguments)) ); } }; return bound; }
function (value) { var i = this.length; while (i--) { if (this[i] === value) { return true; } } return false; }