Keli Chemical Function Thought: A js pre-processing idea; the principle that using function execution can form a scope that is not destroyed can be formed, and all the content that needs to be pre-processed is stored in this scope that is not destroyed can be returned, and a small function will be executed in the small function.
Currying function mainly plays a role in preprocessing;
The function of the bind method: preprocess this in the callback callback method passed in as a context context;
/*** principle of implementation of bind method 1* @param callback [Function] Callback function* @param context [Object] Context* @returns {Function} Change the function pointed to by this*/function bind(callback,context) { var outerArg = Array.prototype.slice.call(arguments,2);// It means to take the parameters after fn and context in the parameters passed in the current scope; return function (){ var innerArg = Array.prototype.slice.call(arguments,0);// It means to take all arguments parameters in the current scope; callback.apply(context,outerArg.concat(innerArg)); }} /*** Imitate the principle of bind implementation on the prototype chain (Korean and chemical function idea)* @param context [Object] Context* @returns {Function} Change the function pointed to by this*/Function.prototype.mybind = function mybind (context) { var _this = this; var outArg = Array.prototype.slice.call(arguments,1); // If('bind' in Function.prototype) { return this.bind.apply(this,[context].concat(outArg)); } // Return in case of incompatibility function () { var inArg = Array.prototype.slice.call(arguments,0); inArg.length === 0?inArg[inArg.length]=window.event:null; var arg = outArg.concat(inArg); _this.apply(context,arg); }}The above is the relevant code for implementing the bind method using Curry functions. I hope it will be helpful for everyone to learn JavaScript programming.