{"id":29384,"date":"2024-11-25T10:22:59","date_gmt":"2024-11-25T02:22:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29384\/"},"modified":"2024-11-25T10:22:59","modified_gmt":"2024-11-25T02:22:59","slug":"es6%e6%96%b0%e7%89%b9%e6%80%a7%e5%bc%80%e5%8f%91%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%ef%bc%8810%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29384\/","title":{"rendered":"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09"},"content":{"rendered":"<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u53ef\u5b50\u7c7b\u5316\u7684\u5185\u5efa\u5bf9\u8c61(Subclassable Built-ins)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5728ES6\u4e2d\uff0c\u50cfArray\uff0cDate\u548cDom\u5143\u7d20\u8fd9\u6837\u7684\u5185\u5efa\u5bf9\u8c61\u90fd\u53ef\u4ee5\u88ab\u5b50\u7c7b\u5316\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/d478b8cd56b9e5aaa8bac3379f461467-0.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u901a\u8fc7\u5b50\u7c7b\u5de5\u5382\u5b9e\u73b0\u7b80\u5355\u7684\u5408\u6210\u5668(Simple mixins via subclass factories)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">mixin\u5728javascript\u91cc\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u79cd\u4ece\u522b\u7684\u5bf9\u8c61&#8221;\u501f\u7528&#8221;\u529f\u80fd\u7684\u65b9\u6cd5\u3002\u6bcf\u4e00\u4e2a\u65b0\u5b9a\u4e49\u7684\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a prototype\u5c5e\u6027\uff0c\u5176\u4ed6\u7684\u5bf9\u8c61\u5c31\u53ef\u4ee5\u4ece\u8fd9\u91cc&#8221;\u501f\u7528&#8221;\u529f\u80fd\u3002\u8fd9\u91cc\u7684\u529f\u80fd\u53ef\u4ee5\u662f\u4e00\u4e2a\u5c5e\u6027\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u65b9\u6cd5\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Mixin\u652f\u6301\u5728\u4e00\u4e2a\u7cfb\u7edf\u4e2d\u964d\u89e3\u529f\u80fd\u7684\u91cd\u590d\u6027,\u589e\u52a0\u529f\u80fd\u7684\u91cd\u7528\u6027\u3002\u5728\u4e00\u4e9b\u5e94\u7528\u7a0b\u5e8f\u4e5f\u8bb8\u9700\u8981\u5728\u6240\u6709\u7684\u5bf9\u8c61\u5b9e\u4f53\u5171\u4eab\u884c\u4e3a\u7684\u5730\u65b9,\u6211\u4eec\u80fd\u591f\u901a\u8fc7\u5728\u4e00\u4e2aMixin\u4e2d\u7ef4\u62a4\u8fd9\u4e2a\u5171\u4eab\u7684\u529f\u80fd,\u6765\u5f88\u5bb9\u6613\u7684\u907f\u514d\u4efb\u4f55\u91cd\u590d,\u800c\u56e0\u6b64\u4e13\u6ce8\u4e8e\u53ea\u5b9e\u73b0\u6211\u4eec\u7cfb\u7edf\u4e2d\u771f\u6b63\u5f7c\u6b64\u4e0d\u540c\u7684\u529f\u80fd\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5728 ES6 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u5168\u65b0\u7684\u57fa\u4e8e\u7c7b\u7ee7\u627f\u7684 \u201cmixin\u201d \u6a21\u5f0f\u8bbe\u8ba1\u66f4\u4f18\u96c5\u7684\u201c\u8bed\u4e49\u5316\u201d\u63a5\u53e3\uff0c\u8fd9\u662f\u56e0\u4e3a ES6 \u4e2d\u7684 extends \u53ef\u4ee5\u7ee7\u627f\u52a8\u6001\u6784\u9020\u7684\u7c7b\uff0c\u8fd9\u4e00\u70b9\u548c\u5176\u4ed6\u7684\u9759\u6001\u58f0\u660e\u7c7b\u7684\u7f16\u7a0b\u8bed\u8a00\u4e0d\u540c\u3002\u5f53 ES6 \u7c7b\u7ee7\u627f\u53e6\u4e00\u4e2a\u7c7b\uff0c\u88ab\u7ee7\u627f\u7684\u7c7b\u53ef\u4ee5\u662f\u901a\u8fc7\u4efb\u610f\u8868\u8fbe\u5f0f\u521b\u5efa\u7684\u52a8\u6001\u7c7b\u3002\u8fd9\u4e2a\u7279\u6027\u53ef\u4ee5\u5141\u8bb8\u5b9e\u73b0\u4e00\u79cd\u5408\u6210\u5668\u6a21\u5f0f\uff0c\u7528\u4e00\u4e2a\u51fd\u6570\u6765\u5c06\u4e00\u4e2a\u7c7b C \u6620\u5c04\u5230\u4e00\u4e2a\u65b0\u7684\u7ee7\u627f\u4e86C\u7684\u7c7b\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">mixin \u5f0f\u7ee7\u627f\u7684\u57fa\u672c\u5f62\u5f0f\uff1a<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/d478b8cd56b9e5aaa8bac3379f461467-1.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe1\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe1\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u7528 mixin \u5b9e\u73b0 Serilizable<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/d478b8cd56b9e5aaa8bac3379f461467-2.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe2\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe2\" \/><\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/d478b8cd56b9e5aaa8bac3379f461467-3.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe3\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe3\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/af16e023a1f653a2c5917730d4d5986a-4.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe4\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe4\" \/><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u7528 ES6 \u7684\u7c7b\u7ee7\u627f\u5b9e\u73b0\u4e86 Serializable\uff0c\u5b83\u68c0\u67e5\u5f53\u524d\u5b9e\u4f8b\u7684\u7c7b\u4e0a\u662f\u5426\u6709\u5b9a\u4e49 stringify \u548c parse \u9759\u6001\u65b9\u6cd5\uff0c\u5982\u679c\u6709\uff0c\u4f7f\u7528\u9759\u6001\u65b9\u6cd5\u91cd\u5199 toString \u65b9\u6cd5\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u5219\u5728\u5b9e\u4f8b\u5316\u5bf9\u8c61\u7684\u65f6\u5019\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\u3002\u7136\u540e\u901a\u8fc7 class Employ extends Serializable(Person) \u6765\u5b9e\u73b0\u53ef\u5e8f\u5217\u5316\uff0c\u5728\u8fd9\u91cc\u6211\u4eec\u6ca1\u6709\u53ef\u5e8f\u5217\u5316 Person \u672c\u8eab\uff0c\u800c\u5c06 Serializable \u5728\u8bed\u4e49\u4e0a\u53d8\u6210\u4e00\u79cd\u4fee\u9970\uff0c\u5373 Employee \u662f\u4e00\u79cd\u53ef\u5e8f\u5217\u5316\u7684 Person\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4f7f\u7528weakmaps\u5b9e\u73b0\u79c1\u6709\u5b9e\u4f8b\u6210\u5458(Private instance members with weakmaps)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Weakmaps\u89e3\u51b3\u4e86\u79c1\u6709\u6570\u636e\u6210\u5458\u7684\u9057\u7559\u95ee\u9898\u3002\u9996\u5148\uff0c\u518d\u4e5f\u6ca1\u6709\u5fc5\u81ea\u5df1\u751f\u6210\u4e00\u4e2a\u552f\u4e00\u7684ID\u4e86\uff0c\u56e0\u4e3a\u8be5\u5bf9\u8c61\u5b9e\u4f8b\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u552f\u4e00ID\u3002\u5176\u6b21\uff0c\u5f53\u4e00\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\u88ab\u5783\u573e\u56de\u6536\uff0c\u7ed1\u5230\u8be5\u5b9e\u4f8b\u4e2d\u7684weakmap\u4e2d\u6240\u6709\u6570\u636e\u4e5f\u4f1a\u88ab\u56de\u6536\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/af16e023a1f653a2c5917730d4d5986a-5.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe5\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe5\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">privateData\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u662f\u4e00\u4e2aWeakMap\u7684\u5b9e\u4f8b \u3002\u5f53\u4e00\u4e2a\u65b0\u7684Shape\u88ab\u521b\u5efa\u65f6\uff0c\u4e00\u4e2aweakmap\u7684\u6761\u76ee\u4f1a\u88ab\u521b\u5efa\u7528\u6765\u4ee5\u4fbf\u8be5\u5b9e\u4f8b\u6765\u4fdd\u5b58\u5305\u542b\u79c1\u6709\u6570\u636e\u7684\u5bf9\u8c61\u3002\u5728weakmap\u4e2d\u6700\u5173\u952e\u7684\u662fthis \uff0c\u5373\u4f7f\u5bf9\u4e8e\u5f00\u53d1\u8005\u6765\u8bf4\u83b7\u53d6\u4e00\u4e2aShape\u5bf9\u8c61\u7684\u5f15\u7528\u662f\u5fae\u4e0d\u8db3\u9053\u7684\u4e00\u4ef6\u4e8b\uff0c\u4ed6\u4eec\u4e5f\u65e0\u6cd5\u4ece\u5b9e\u4f8b\u5916\u6765\u8bbf\u95ee\u5230privateData\uff0c\u6240\u4ee5\uff0c\u6570\u636e\u88ab\u4ece\u9ebb\u70e6\u5236\u9020\u8005\u624b\u4e2d\u5b89\u5168\u4fdd\u62a4\u4e86\u3002\u4efb\u4f55\u60f3\u8981\u64cd\u7eb5\u79c1\u6709\u6570\u636e\u7684\u65b9\u6cd5\u53ea\u80fd\u591f\u901a\u8fc7\u4f20\u5165\u5b9e\u4f8b\u7684this \uff0c\u4ece\u800c\u62ff\u5230\u8fd4\u56de\u7684\u5bf9\u8c61\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c getName()\u4f1a\u83b7\u53d6\u5bf9\u8c61\u5e76\u8fd4\u56dename\u5c5e\u6027\u7684\u503c\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5c3e\u8c03\u7528\u4f18\u5316(Tail-call optimization)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5c3e\u8c03\u7528(Tail Call)\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u4e00\u4e2a\u91cd\u8981\u6982\u5ff5\uff0c\u662f\u6307\u67d0\u4e2a\u51fd\u6570\u7684\u6700\u540e\u4e00\u6b65\u662f\u8c03\u7528\u53e6\u4e00\u4e2a\u51fd\u6570\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5c3e\u8c03\u7528\u4f18\u5316\u662f\u4e3a\u4e86\u907f\u514d\u4e0d\u65ad\u4fdd\u7559\u548c\u521b\u5efa\u65b0\u7684\u8c03\u7528\u6808\uff0c\u800c\u5728\u51fd\u6570\u6700\u540e\u4e00\u6b65\u8c03\u7528\u53e6\u4e00\u4e2a\u51fd\u6570\u3002\u6700\u540e\u4e00\u6b65\u7684\u610f\u4e49\u5c31\u5728\u4e8e\uff1a\u4e0d\u9700\u8981\u4fdd\u7559\u5f53\u524d\u51fd\u6570\u7684\u6267\u884c\u73af\u5883\uff0c\u5728\u8c03\u7528\u7684\u4e0b\u4e00\u4e2a\u51fd\u6570\u6267\u884c\u5b8c\u6bd5\u5e76\u7ed9\u51fa\u8fd4\u56de\u503c\u540e\uff0c\u76f4\u63a5\u518d\u8fd4\u56de\uff0c\u7c7b\u4f3c\u4e8epipe\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u51fd\u6570\u8c03\u7528\u81ea\u8eab\uff0c\u79f0\u4e3a\u9012\u5f52\u3002\u5982\u679c\u5c3e\u8c03\u7528\u81ea\u8eab\uff0c\u5c31\u79f0\u4e3a\u5c3e\u9012\u5f52\u3002\u5c3e\u9012\u5f52(Tail-recursion)\u5c31\u662f\u5229\u7528\u5c3e\u8c03\u4f18\u5316\u7684\u7279\u6027\uff0c\u4ece\u8bed\u8a00\u673a\u5236\u4e0a\u8fdb\u884c\u9012\u5f52\u64cd\u4f5c\u7684\u4f18\u5316\uff0c\u9632\u6b62\u5806\u6808\u6ea2\u51fa(stack overflow)\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">&#8220;\u5c3e\u8c03\u7528\u4f18\u5316&#8221;\u5bf9\u9012\u5f52\u64cd\u4f5c\u610f\u4e49\u91cd\u5927\uff0c\u6240\u4ee5\u4e00\u4e9b\u51fd\u6570\u5f0f\u7f16\u7a0b\u8bed\u8a00\u5c06\u5176\u5199\u5165\u4e86\u8bed\u8a00\u89c4\u683c\u3002ES6\u4e5f\u662f\u5982\u6b64\uff0c\u7b2c\u4e00\u6b21\u660e\u786e\u89c4\u5b9a\uff0c\u6240\u6709 ECMAScript \u7684\u5b9e\u73b0\uff0c\u90fd\u5fc5\u987b\u90e8\u7f72&#8221;\u5c3e\u8c03\u7528\u4f18\u5316&#8221;\u3002\u8fd9\u5c31\u662f\u8bf4\uff0c\u5728 ES6 \u4e2d\uff0c\u53ea\u8981\u4f7f\u7528\u5c3e\u9012\u5f52\uff0c\u5c31\u4e0d\u4f1a\u53d1\u751f\u6808\u6ea2\u51fa\uff0c\u76f8\u5bf9\u8282\u7701\u5185\u5b58\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u9012\u5f52\u975e\u5e38\u8017\u8d39\u5185\u5b58\uff0c\u56e0\u4e3a\u9700\u8981\u540c\u65f6\u4fdd\u5b58\u6210\u5343\u4e0a\u767e\u4e2a\u8c03\u7528\u5e27\uff0c\u5f88\u5bb9\u6613\u53d1\u751f\u201c\u6808\u6ea2\u51fa\u201d\u9519\u8bef(stack overflow)\u3002\u4f46\u5bf9\u4e8e\u5c3e\u9012\u5f52\u6765\u8bf4\uff0c\u7531\u4e8e\u53ea\u5b58\u5728\u4e00\u4e2a\u8c03\u7528\u5e27\uff0c\u6240\u4ee5\u6c38\u8fdc\u4e0d\u4f1a\u53d1\u751f\u201c\u6808\u6ea2\u51fa\u201d\u9519\u8bef\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4e0b\u9762\u4ee3\u7801\u662f\u4e00\u4e2a\u9636\u4e58\u51fd\u6570\uff0c\u8ba1\u7b97n\u7684\u9636\u4e58\uff0c\u6700\u591a\u9700\u8981\u4fdd\u5b58n\u4e2a\u8c03\u7528\u8bb0\u5f55\uff0c\u590d\u6742\u5ea6 O(n)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/af16e023a1f653a2c5917730d4d5986a-6.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe6\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe6\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5982\u679c\u6539\u6210\u5c3e\u9012\u5f52\u8c03\u7528\uff0c\u53ea\u4fdd\u7559\u4e00\u4e2a\u8c03\u7528\u8bb0\u5f55\uff0c\u590d\u6742\u5ea6 O(1)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/af16e023a1f653a2c5917730d4d5986a-7.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe7\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe7\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u8ba1\u7b97fibonacci\u6570\u5217\uff0c\u80fd\u5145\u5206\u8bf4\u660e\u5c3e\u9012\u5f52\u4f18\u5316\u7684\u91cd\u8981\u6027<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/9da1baedd8dfe9e0daa6f4dd3f85ae76-8.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe8\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe8\" \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4f7f\u7528\u5c3e\u9012\u5f52\u4f18\u5316\u8fc7\u7684fibonacci \u9012\u5f52\u7b97\u6cd5<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/9da1baedd8dfe9e0daa6f4dd3f85ae76-9.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe9\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe9\" \/><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u81ea\u5b9a\u4e49\u9519\u8bef\u7c7b(Custom Errors)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Error\u662fJavaScript\u4e2d\u7684\u9519\u8bef\u7c7b\uff0c\u5b83\u540c\u65f6\u4e5f\u662f\u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u4e00\u4e2a\u9519\u8bef\u5bf9\u8c61\u3002Error\u5b9e\u4f8b\u4f1a\u5728\u53d1\u751f\u8fd0\u884c\u8fdb\u9519\u8bef\u65f6\u629b\u51fa\uff0cError\u50cf\u5176\u5b83\u5bf9\u8c61\u4e00\u6837\uff0c\u4e5f\u53ef\u4ee5\u7531\u7528\u6237\u81ea\u5b9a\u4e49\u521b\u5efa\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">ES6\u901a\u8fc7\u6d3e\u751f\u5b9e\u73b0\u81ea\u5b9a\u4e49\u9519\u8bef\u7c7b<\/span><\/p>\n<p style=\"line-height: 2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/9da1baedd8dfe9e0daa6f4dd3f85ae76-10.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe10\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u63d2\u56fe10\" \/><br \/><\/span><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0810\uff09\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53ef\u5b50\u7c7b\u5316\u7684\u5185\u5efa\u5bf9\u8c61(Subclassable Built-ins) \u5728ES6\u4e2d\uff0c\u50cfArray\uff0cDate\u548cDom\u5143\u7d20\u8fd9\u6837\u7684\u5185\u5efa\u5bf9\u8c61\u90fd\u53ef\u4ee5\u88ab\u5b50\u7c7b\u5316\u3002 \u901a\u8fc7\u5b50\u7c7b\u5de5\u5382\u5b9e\u73b0\u7b80\u5355\u7684\u5408\u6210\u5668(Simple mixins via subclass factories) mixin\u5728javascript\u91cc\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u79cd\u4ece\u522b\u7684\u5bf9\u8c61&#8221;\u501f\u7528&#8221;\u529f\u80fd\u7684\u65b9\u6cd5\u3002\u6bcf\u4e00\u4e2a\u65b0\u5b9a\u4e49\u7684\u5bf9\u8c61\u90fd\u6709\u4e00\u4e2a prototype\u5c5e\u6027\uff0c\u5176\u4ed6\u7684\u5bf9\u8c61\u5c31\u53ef\u4ee5\u4ece\u8fd9\u91cc&#8221;\u501f\u7528&#8221;\u529f\u80fd\u3002\u8fd9\u91cc\u7684\u529f\u80fd\u53ef\u4ee5\u662f\u4e00\u4e2a\u5c5e\u6027\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u65b9\u6cd5\u3002 Mixin\u652f\u6301\u5728\u4e00\u4e2a\u7cfb\u7edf\u4e2d\u964d\u89e3\u529f\u80fd\u7684\u91cd\u590d\u6027,\u589e\u52a0\u529f\u80fd\u7684\u91cd\u7528\u6027\u3002\u5728\u4e00\u4e9b\u5e94\u7528\u7a0b\u5e8f\u4e5f\u8bb8\u9700\u8981\u5728\u6240\u6709\u7684\u5bf9\u8c61\u5b9e\u4f53\u5171\u4eab\u884c\u4e3a\u7684\u5730\u65b9,\u6211\u4eec\u80fd\u591f\u901a\u8fc7\u5728\u4e00\u4e2aMixin\u4e2d\u7ef4\u62a4\u8fd9\u4e2a\u5171\u4eab\u7684\u529f\u80fd,\u6765\u5f88\u5bb9\u6613\u7684\u907f\u514d\u4efb\u4f55\u91cd\u590d,\u800c\u56e0\u6b64\u4e13\u6ce8\u4e8e\u53ea\u5b9e\u73b0\u6211\u4eec\u7cfb\u7edf\u4e2d\u771f\u6b63\u5f7c\u6b64\u4e0d\u540c\u7684\u529f\u80fd\u3002 \u5728 ES6 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u91c7\u7528\u5168\u65b0\u7684\u57fa\u4e8e\u7c7b\u7ee7\u627f\u7684 \u201cmixin\u201d \u6a21\u5f0f\u8bbe\u8ba1\u66f4\u4f18\u96c5\u7684\u201c\u8bed\u4e49\u5316\u201d\u63a5\u53e3\uff0c\u8fd9\u662f\u56e0\u4e3a ES6 \u4e2d\u7684 extends \u53ef\u4ee5\u7ee7\u627f\u52a8\u6001\u6784\u9020\u7684\u7c7b\uff0c\u8fd9\u4e00\u70b9\u548c\u5176\u4ed6\u7684\u9759\u6001\u58f0\u660e\u7c7b\u7684\u7f16\u7a0b\u8bed\u8a00\u4e0d\u540c\u3002\u5f53 ES6 \u7c7b\u7ee7\u627f\u53e6\u4e00\u4e2a\u7c7b\uff0c\u88ab\u7ee7\u627f\u7684\u7c7b\u53ef\u4ee5\u662f\u901a\u8fc7\u4efb\u610f\u8868\u8fbe\u5f0f\u521b\u5efa\u7684\u52a8\u6001\u7c7b\u3002\u8fd9\u4e2a\u7279\u6027\u53ef\u4ee5\u5141\u8bb8\u5b9e\u73b0\u4e00\u79cd\u5408\u6210\u5668\u6a21\u5f0f\uff0c\u7528\u4e00\u4e2a\u51fd\u6570\u6765\u5c06\u4e00\u4e2a\u7c7b C \u6620\u5c04\u5230\u4e00\u4e2a\u65b0\u7684\u7ee7\u627f\u4e86C\u7684\u7c7b\u3002 mixin \u5f0f\u7ee7\u627f\u7684\u57fa\u672c\u5f62\u5f0f\uff1a \u7528 mixin \u5b9e\u73b0 Serilizable \u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u7528 ES6 \u7684\u7c7b\u7ee7\u627f\u5b9e\u73b0\u4e86 Serializable\uff0c\u5b83\u68c0\u67e5\u5f53\u524d\u5b9e\u4f8b\u7684\u7c7b\u4e0a\u662f\u5426\u6709\u5b9a\u4e49 stringify \u548c parse \u9759\u6001\u65b9\u6cd5\uff0c\u5982\u679c\u6709\uff0c\u4f7f\u7528\u9759\u6001\u65b9\u6cd5\u91cd\u5199 toString \u65b9\u6cd5\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u5219\u5728\u5b9e\u4f8b\u5316\u5bf9\u8c61\u7684\u65f6\u5019\u629b\u51fa\u4e00\u4e2a\u5f02\u5e38\u3002\u7136\u540e\u901a\u8fc7 class Employ extends Serializable(Person) \u6765\u5b9e\u73b0\u53ef\u5e8f\u5217\u5316\uff0c\u5728\u8fd9\u91cc\u6211\u4eec\u6ca1\u6709\u53ef\u5e8f\u5217\u5316 Person \u672c\u8eab\uff0c\u800c\u5c06 Serializable \u5728\u8bed\u4e49\u4e0a\u53d8\u6210\u4e00\u79cd\u4fee\u9970\uff0c\u5373 Employee \u662f\u4e00\u79cd\u53ef\u5e8f\u5217\u5316\u7684 Person\u3002 \u4f7f\u7528weakmaps\u5b9e\u73b0\u79c1\u6709\u5b9e\u4f8b\u6210\u5458(Private instance members [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-29384","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=29384"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29384\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}