function demo(a, b) {
console.log(a);
console.log(b);
console.log(this.value);
}
Function.prototype.call1 = function(context) {
context = context || {};
let self = this;
let args = [];
for (let i = 1; i < arguments.length; i++) {
args.push(eval("arguments[" + i + "]"));
}
context.fn = self;
context.fn(...args);
delete context.fn;
};
Function.prototype.Apply1 = function(context) {
context = context || {};
let self = this;
context.fn = self;
context.fn(...arguments[1]);
delete context.fn;
};
demo.call1(
{
value: "call1"
},
"a",
"b"
);
demo.Apply1(
{
value: "apply1"
},
["c", "d"]
);