# 手写 call 和 apply
Function.prototype.call2 = function(ctx, ...params) {
if (typeof ctx == 'object') {
ctx = ctx || window;
} else {
ctx = Object(ctx);
}
ctx.fn = this;
var result = ctx.fn(...params);
delete ctx.fn;
return result;
};
var name = 'windowName';
var obj = {
name: 'obgMarin',
};
function getName(age, name) {
console.log(this.name);
console.log(age, name);
}
getName.call2(obj, 12, '123');
getName.call2(null, 12, '123');