Function.prototype.myapply = function (context, args) { context = context || window context.fn = this let result if (!args) { result = context.fn() } else { let temp = [] for (let i = 0, len = args.length; i < len; i++) { temp.push('args[' + i + ']') } result = eval('context.fn(' + temp + ')') } delete context.fn return result }