FED12. Function.bind
描述
请补全JavaScript代码,要求实现Function.bind函数的功能且该新函数命名为"_bind"。示例1
输入:
Fn._bind(object)
输出:
HTML/CSS/JavaScript 解法, 执行用时: 1680ms, 内存消耗: 77800KB, 提交时间: 2022-02-09
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n // 补全代码\n // var res = obj.fn.bind(target)\n // res()\n Function.prototype._bind = function (target) {\n if (typeof this !== 'function') {\n throw new TypeError('what is to be a function')\n }\n let _this = this\n let args = Array.prototype.slice.call(arguments, 1)\n let bound = function () {\n return _this.apply(this instanceof _this ? this : target, [...arguments].concat(args))\n }\n let fn = function () {}\n fn.prototype = this.prototype\n bound.prototype = new fn()\n bound.prototype.constructor = bound\n return bound\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1740ms, 内存消耗: 77848KB, 提交时间: 2021-12-18
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n // 补全代码\n Function.prototype._bind = function(obj = window, ...args){\n return (...rest) => this.call(obj, ...args, ...rest);\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1741ms, 内存消耗: 77772KB, 提交时间: 2022-02-03
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n // 补全代码\n Function.prototype._bind=function(obj){\n let that=this;\n return (...pram)=>{\n return that.apply(obj,pram);\n }\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1741ms, 内存消耗: 77800KB, 提交时间: 2022-01-29
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n // 补全代码\n Function.prototype._bind = function(target = window, ...args) {\n let fn = this\n return function () {\n return fn.apply(target, args)\n }\n}\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1743ms, 内存消耗: 77772KB, 提交时间: 2021-12-16
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n // 补全代码\n Function.prototype._bind = function(obj){\n return this.bind(obj)\n }\n </script>\n </body>\n</html>","libs":[]}