UNPKG

zts-js-polyfill

Version:

33 lines (27 loc) 790 B
Function.prototype.myBind = function() { var arr = [] if (typeof arguments[0] == "object") { arguments[0].funct = this; for (const key of arguments) { arr.push(key) } arguments[0].funct.arguments = arr return arguments[0] } else { var obj = {}; obj.funct = this; for (const key of arguments) { arr.push(key) } obj.funct.arguments = arr return obj } } // myBind函数测试用例 var func = function() { return this.a + Array.prototype.slice.call(arguments); } console.log(func.myBind(1, 2, 3).funct()) // 输出“undefined2,3" console.log(func.myBind({ a: 1000 }, 1, 2, 3).funct(4, 5, 6)) // 输出"10001,2,3,4,5,6"