1234567891011121314151617181920212223242526 |
- const obj = {
- name: 'yibo'
- }
- function fn(a, b) {
- console.log(this)
- console.log(a + b)
- return a + b
- }
- function myBind(obj) {
- const context = this
- const newArguments = Array.prototype.slice.call(arguments)
- newArguments.shift()
- return function () {
- return context.apply(obj, newArguments)
- }
- }
- const res = fn(1, 2)
- console.log(res)
- Function.prototype.myBind = myBind
- const myFn = fn.myBind(obj, 5, 8)
- const res2 = myFn()
- console.log(res2)
|