1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
const person = { show: function (age, weapon) { console.log(this.name + ', age: ' + age + ', weapon: ' + weapon) } }
const obj = { name: 'tan' }
person.show.apply(obj, [200])
Function.prototype._apply = function (ctx) { ctx = ctx || Window ctx.fn = this const _args = arguments[1] || [] const res = ctx.fn(..._args) delete ctx.fn return res }
person.show._apply(obj, [500, 'AK'])
|