First, start
Let's start by looking at what the native call did.
function Bar (name,age) { this. Hobby = ' shopping'; Console.log (this. value); Console.log (this. Hobby); Console.log (name); = ' Kevin '; var obj = { ' gamming '}var hah = bar.call (obj, ' Jack ', 18);
The output is:
This means that call just modifies the point of this and there is no return object.
Second, the simulation realization
So all we have to do is try to change the point of this and execute it, no return value is required:
function () { var dir = arguments[0]; var args = []; for (var i = 1; i < arguments.length; i++) { args.push (arguments[i]) }; This ; // Here's a new feature of ES6, not good . Dir.pau (... args); Delete Dir.pau;}
If it's not like using ES6, the way I look at others is using eval, but I don't know eval ...
Eval (' Dir.pau (' + args + ') 'delete Dir.pau;
Third, apply
Apply just turns the situation of call one parameter to pass an array directly, and does not have much change, here does not continue to write
Analog implementation of Javascript call and apply