JSFiddle - React, Tailwind, and code Playground
JavaScript
if (!Function.prototype.bind2) {
Function.prototype.bind2 = function (oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function () {},
fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
console.log('bind arguments:');
console.log(arguments);
console.log('aArgs:');
console.log(aArgs);
console.log('Slice arguments:');
console.log(Array.prototype.slice.call(arguments));
console.log('Concat slice arguments:');
console.log(aArgs.concat(Array.prototype.slice.call(arguments)));
return fBound;
};
}
var x = function ( ) {
console.log('x() arguments: ');
console.log(arguments);
return this.value;
}.bind2({value: 666}, 1, 2, 3);
console.log(x( )); // 666