The following small make up will bring you an article on using the Keri function in javascript to implement the bind method [recommended ]. I think this is quite good. Now I will share it with you and give you a reference. Let's take a look at Ke's function thought: A js pre-processing idea; using function execution can form a principle of no-destruction scope, store all the content to be pre-processed in this non-destruction scope, and return a small function, in the future, we will execute all the small functions. In the small functions, we can perform operations on the previously stored values;
• Keri functions are mainly used for preprocessing;
• Bind method: preprocesses this in the passed callback method as context;
/*** Bind method implementation principle 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); // indicates the parameters in the current scope except fn and context; return function () {var innerArg = Array. prototype. slice. call (arguments, 0); // indicates taking all the arguments parameters in the current scope; callback. apply (context, outerArg. concat (innerArg ));}}
/*** Simulate the bind implementation principle on the prototype chain (KE Physical Function Idea) * @ param context [Object] context * @ returns {Function} changes the Function that this points to */Function. prototype. mybind = function mybind (context) {var _ this = this; var outArg = Array. prototype. slice. call (arguments, 1); // if ('bind' in Function with compatibility. prototype) {return this. bind. apply (this, [context]. concat (outArg);} // return function () {var inArg = Array. prototype. slice. call (argument S, 0); inArg. length = 0? InArg [inArg. length] = window. event: null; var arg = outArg. concat (inArg); _ this. apply (context, arg );}}
In the above javascript article, the bind method implemented by using the Keri function [recommended] is all the content shared by the editor. I hope to give you a reference and support for your feet.