题解 | #实现new操作符#

实现new操作符

https://www.nowcoder.com/practice/71c2aff7cb6641099aa17d56157a91b9

{"html":"<!DOCTYPE html>\n<html>\n    <head>\n        <meta charset=utf-8>\n    </head>\n    <body>\n    \t\n        <script type=\"text/javascript\">\n            const _new = function() {\n                // 补全代码\n                const obj = {};\n                const fn = [].shift.call(arguments);\n\n                if(typeof fn.prototype === 'object') {\n                    obj.__proto__ = fn.prototype;\n                }\n\n                const res = fn.apply(obj, [...arguments]);\n\n                return typeof res === 'object' ? res : obj;\n            }\n        </script>\n    </body>\n</html>","css":"","js":""}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务