题解 | #实现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(Contructor) {\n                // 补全代码\n                var obj = {}\n                obj.__proto__ = Contructor.prototype\n                var args = Array.prototype.slice.call(arguments, 1)\n                var result = Contructor.apply(obj, args)\n                if(typeof result === 'object' && result !== null) {\n                    return result\n                }\n                return obj\n            }\n        </script>\n    </body>\n</html>","css":"","js":""}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务