{"id":379,"date":"2019-01-15T23:42:04","date_gmt":"2019-01-15T15:42:04","guid":{"rendered":"https:\/\/wp.winter-weng.cc\/work\/?p=379"},"modified":"2019-01-15T23:42:04","modified_gmt":"2019-01-15T15:42:04","slug":"ch-11-%e8%a1%8c%e7%82%ba%e5%a7%94%e6%b4%be","status":"publish","type":"post","link":"https:\/\/wp.winter-weng.cc\/work\/?p=379","title":{"rendered":"Ch.11 \u884c\u70ba\u59d4\u6d3e"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_75 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"\u986f\u793a\/\u96b1\u85cf\u5167\u5bb9\u76ee\u9304\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E6%8E%A1%E7%94%A8%E5%A7%94%E6%B4%BE%E5%B0%8E%E5%90%91%E7%9A%84%E8%A8%AD%E8%A8%88\" >\u63a1\u7528\u59d4\u6d3e\u5c0e\u5411\u7684\u8a2d\u8a08<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E9%A1%9E%E5%88%A5%E7%90%86%E8%AB%96\" >\u985e\u5225\u7406\u8ad6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E5%A7%94%E6%B4%BE%E7%90%86%E8%AB%96\" >\u59d4\u6d3e\u7406\u8ad6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E6%AF%94%E8%BC%83%E5%BF%83%E6%99%BA%E6%A8%A1%E5%9E%8B\" >\u6bd4\u8f03\u5fc3\u667a\u6a21\u578b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E9%A1%9E%E5%88%A5_vs_%E7%89%A9%E4%BB%B6\" >\u985e\u5225 vs. \u7269\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E8%BC%83%E7%82%BA%E7%B0%A1%E5%96%AE%E7%9A%84%E8%A8%AD%E8%A8%88\" >\u8f03\u70ba\u7c21\u55ae\u7684\u8a2d\u8a08<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E6%9B%B4%E5%A5%BD%E7%9A%84%E8%AA%9E%E6%B3%95\" >\u66f4\u597d\u7684\u8a9e\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E5%85%A7%E7%9C%81_Introspection\" >\u5167\u7701 (Introspection)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E8%A4%87%E7%BF%92\" >\u8907\u7fd2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/wp.winter-weng.cc\/work\/?p=379\/#%E9%99%84%E9%8C%84_D_%E2%80%93_ES6_%E9%A1%9E%E5%88%A5\" >\u9644\u9304 D\u00a0&#8211;\u00a0ES6\u00a0\u985e\u5225<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>\u8907\u7fd2\u7b2c 10 \u7ae0\uff0c[[Prototype]] \u6a5f\u5236\u662f\u5b58\u5728\u4e00\u500b\u7269\u4ef6\u4e0a\uff0c\u53c3\u8003\u4e86\u53e6\u4e00\u500b\u7269\u4ef6\u7684\u4e00\u7a2e<strong>\u5167\u90e8\u9023\u7d50<\/strong>\u3002\u9019\u7a2e\u9023\u7d50\u6703\u5728\u5c0d\u7269\u4ef6\u9032\u884c\u7279\u6027\u6216\u65b9\u6cd5\u7684\u53c3\u8003\u6642\uff0c<strong>\u7279\u6027\u4e0d\u5b58\u5728<\/strong>\u7684\u60c5\u6cc1\u4e0b\u767c\u63ee\u4f5c\u7528\u3002\u7576\u767c\u751f\u9019\u7a2e\u60c5\u6cc1\u6642\uff0c[[Prototype]] \u6703\u544a\u8a34\u5f15\u64ce\u5faa\u8457\u9023\u7d50\u67e5\u627e\uff0c\u4e00\u76f4\u5faa\u5e8f\u5c0b\u627e\u4e0b\u53bb\u3002\u4e00\u9023\u4e32\u7684\u9023\u7d50\u5c31\u662f\u300c\u539f\u578b\u93c8 (prototype chain)\u300d\u3002<\/p>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%8E%A1%E7%94%A8%E5%A7%94%E6%B4%BE%E5%B0%8E%E5%90%91%E7%9A%84%E8%A8%AD%E8%A8%88\"><\/span><strong>\u63a1\u7528\u59d4\u6d3e\u5c0e\u5411\u7684\u8a2d\u8a08<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<p>\u4ee5\u76f4\u622a\u4e86\u7576\u7684\u65b9\u5f0f\u63a1\u7528 [[Prototype]]\uff0c\u5fc5\u9808\u5f9e\u985e\u5225 \/ \u7e7c\u627f\u8a2d\u8a08\u6a21\u5f0f\u6539\u70ba\u884c\u70ba\u59d4\u6d3e (behavior delegation) \u8a2d\u8a08\u6a21\u5f0f\u3002<\/p>\n\n\n<p>\u5148\u9032\u884c\u4e00\u4e9b\u7406\u8ad6\u4e0a\u7684\u7df4\u7fd2\uff0c\u8003\u91cf\u7576\u6211\u5011\u6709\u591a\u500b\u985e\u4f3c\u4efb\u52d9 (\u4f8b\u5982 XYZ\u3001ABC \u7b49) \u7684\u60c5\u5883\uff1a<\/p>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%A1%9E%E5%88%A5%E7%90%86%E8%AB%96\"><\/span>\u985e\u5225\u7406\u8ad6<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<ul class=\"wp-block-list\"><li>\u62bd\u53d6\u76f8\u4f3c\u4efb\u52d9\u4f86\u5b9a\u7fa9\u5171\u901a\u884c\u70ba\uff0c\u4f5c\u70ba\u7236\u985e\u5225 Task\u3002<\/li><li>\u5b9a\u7fa9\u5b50\u985e\u5225 XYZ \u8207 ABC\uff0c\u4e26\u7e7c\u627f\u81ea Task\u3002<\/li><li>\u65b0\u589e\u5b50\u985e\u5225\u7279\u5316\u7684\u884c\u70ba\uff0c\u8986\u5beb (overriding)\u3001\u591a\u578b (polymorphism)<\/li><li>\u5be6\u9ad4\u5316\u51fa\u5b50\u985e\u5225 XYZ \u7684\u62f7\u8c9d (copies)\uff0c\u4e26\u4f7f\u7528\u5be6\u9ad4 (instance) \u57f7\u884c\u4efb\u52d9\u3002\u5be6\u9ad4\u5177\u6709 Task \u5b9a\u7fa9\u7684\u884c\u70ba\uff0c\u4e5f\u5177\u6709 XYZ \u5b9a\u7fa9\u7684\u884c\u70ba\u3002ABC \u4e5f\u6703\u6709\u5c08\u5c6c\u81ea\u5df1\u7684\u884c\u70ba\u3002<\/li><li>\u5be6\u9ad4\u5316\u5f8c\u53ea\u6703\u8207\u5be6\u9ad4\u4e92\u52d5\uff0c\u4e0d\u6703\u8207\u985e\u5225\u4e92\u52d5\u3002<\/li><\/ul>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%A7%94%E6%B4%BE%E7%90%86%E8%AB%96\"><\/span>\u59d4\u6d3e\u7406\u8ad6<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<ul class=\"wp-block-list\"><li>\u5b9a\u7fa9\u4e00\u500b Task <strong>\u7269\u4ef6<\/strong>\u3002<\/li><li>\u5c0d\u7279\u5b9a\u4efb\u52d9 (XYZ\u3001ABC) \u5b9a\u7fa9\u7269\u4ef6\u4f86\u6301\u6709\u8a72\u4efb\u52d9\u5c08\u5c6c\u7684\u884c\u70ba\u3002<\/li><li>\u7279\u5b9a\u4efb\u52d9\u6703\u9023\u7d50\u5230 Task \u4e0a\uff0c\u5c07 XYZ \u59d4\u6d3e\u7d66 Task\u3002<\/li><\/ul>\n\n\n<p>\u4f5c\u8005\u7a31\u9019\u7a2e\u98a8\u683c\u70ba OLOO (objects linked to other objects)\u3002\u8acb\u6ce8\u610f\u5176\u4ed6\u7684\u4e00\u4e9b\u7279\u6027\uff1a<\/p>\n\n\n<ol class=\"wp-block-list\"><li>\u8cc7\u6599\u7279\u6027\u3001\u72c0\u614b (state) \u76f4\u63a5\u4f4d\u65bc\u59d4\u6d3e\u8005 (XYZ) \u4e0a\u3002<\/li><li>\u5728\u985e\u5225\u8a2d\u8a08\u6a21\u5f0f\u4e2d\uff0c\u6703\u4f7f\u7528\u540c\u540d\u7684 mehod\uff0c\u4ee5\u9032\u884c\u591a\u578b\u3002\u4f46\u5728\u884c\u70ba\u59d4\u6d3e\u4e2d\uff0c\u76e1\u53ef\u80fd\u5730<strong>\u907f\u514d<\/strong>\u5728 [[Prototype]] \u4e32\u93c8\u7684\u4e0d\u540c\u5c64\u7d1a\u4e0a\u70ba\u6771\u897f\u53d6\u76f8\u540c\u540d\u7a31\u3002\u4f7f\u7528\u63cf\u8ff0\u6027\u65b9\u6cd5\u540d\u7a31\uff0c\u8aaa\u660e\u6bcf\u500b\u7269\u4ef6\u5c08\u5c6c\u7684\u884c\u70ba\u3002<\/li><li>\u4f7f\u7528\u4e00\u500b XYZ \u7684\u65b9\u6cd5\u537b\u627e\u4e0d\u5230\u6642\uff0c\u6703\u4f9d\u5faa\u9023\u7d50\u524d\u5f80 Task \u5c0b\u627e\uff0c\u6b64\u6642\u96d6\u7136\u65b9\u6cd5\u662f Task \u7684\uff0c\u4f46\u96b1\u542b\u7684 this \u7e6b\u7d50\u6703\u662f XYZ\u3002<\/li><li>\u76f8\u4e92\u59d4\u6d3e\u662f\u4e0d\u5141\u8a31\u7684\uff0c\u5728\u8a2d\u5b9a\u6642\u671f\u5c31\u6703\u88ab\u99c1\u56de\u3002<\/li><\/ol>\n\n\n<p class=\"has-text-color has-vivid-red-color\">\u884c\u70ba\u59d4\u6d3e\u6240\u4ee3\u8868\u7684\u610f\u7fa9\u662f\uff0c\u7576\u67d0\u4e9b\u7269\u4ef6\u5728\u81ea\u8eab (XYZ) \u627e\u4e0d\u5230\u7279\u6027\u6216\u65b9\u6cd5\u6642\uff0c\u80fd\u5920\u9032\u884c\u59d4\u6d3e (\u7d66 Task)\u3002<\/p>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%AF%94%E8%BC%83%E5%BF%83%E6%99%BA%E6%A8%A1%E5%9E%8B\"><\/span>\u6bd4\u8f03\u5fc3\u667a\u6a21\u578b<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<p>\u8acb\u76f4\u63a5\u53c3\u8003\u66f8\u672c P.201~205 (\u6216\u662f<a href=\"https:\/\/github.com\/getify\/You-Dont-Know-JS\/blob\/master\/this%20%26%20object%20prototypes\/ch6.md#mental-models-compared\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"\u9019\u88e1 (\u5728\u65b0\u5206\u9801\u4e2d\u958b\u555f)\">\u9019\u88e1<\/a>)\uff0c\u770b\u4e00\u904d\u4e0d\u61c2\uff0c\u53ef\u4ee5\u591a\u770b\u5e7e\u904d\uff01<\/p>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%A1%9E%E5%88%A5_vs_%E7%89%A9%E4%BB%B6\"><\/span><strong>\u985e\u5225 vs. \u7269\u4ef6<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<p>\u6b64\u7bc0\u4e2d\uff0c\u4ee5\u88fd\u4f5c\u4e00\u500b UI Widget \u70ba\u5be6\u4f8b\u4ecb\u7d39\u985e\u5225\u98a8\u683c\u3001ES6\u3001\u59d4\u6d3e\u4e09\u8005\u5be6\u4f5c\u7684\u5dee\u7570\u3002ES6 \u7684 class \u53ea\u662f\u8a9e\u6cd5\u7cd6\uff0c\u4f9d\u7136\u662f\u904b\u4f5c\u65bc [[Prototype]] \u6a5f\u5236\u4e4b\u4e0a\u3002\u5728 OLOO \u98a8\u683c\u4e2d\uff1a<\/p>\n\n\n<ul class=\"wp-block-list\"><li>Widget \u53ea\u662f\u4e00\u500b\u7269\u4ef6\uff0c\u662f\u4e00\u500b\u5de5\u5177\u7684\u96c6\u5408\u3002<\/li><li>\u8207\u985e\u5225\u4e0d\u540c\uff0cOLOO \u5efa\u8b70\u63a1\u7528\u4e0d\u540c\u4e14\u8f03\u5177\u63cf\u8ff0\u6027\u7684\u540d\u7a31\u3002<\/li><li>\u8a9e\u6cd5\u4e0a\u6c92\u6709\u51fa\u73fe\u4efb\u4f55 <code>constructor<\/code>\u3001<code>.prototype<\/code> \u6216 <code>new<\/code>\u3002<\/li><li>\u5275\u5efa (construction) \u8207\u521d\u59cb\u5316 (initialization) \u80fd\u5920\u5206\u958b\u9032\u884c\uff0c\u66f4\u5b8c\u5584\u652f\u63f4\u95dc\u6ce8\u9ede\u5206\u96e2 (separation of concerns) \u7684\u539f\u5247\u3002<\/li><\/ul>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%BC%83%E7%82%BA%E7%B0%A1%E5%96%AE%E7%9A%84%E8%A8%AD%E8%A8%88\"><\/span><strong>\u8f03\u70ba\u7c21\u55ae\u7684\u8a2d\u8a08<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<p>\u6b64\u7bc0\u518d\u63d0\u4f9b\u53e6\u4e00\u500b\u7bc4\u4f8b\u3002\u8aaa\u660e\u884c\u70ba\u59d4\u6d3e\u6a21\u5f0f\u7684\u512a\u9ede\uff1a<\/p>\n\n\n<ul class=\"wp-block-list\"><li>\u7269\u4ef6\u662f\u5f7c\u6b64\u7684\u6c34\u5e73\u540c\u5115\u3002<\/li><li>\u6e1b\u5c11\u5be6\u9ad4\u7684\u6578\u91cf\u3002<\/li><li>\u4e0d\u9700\u8981\u9032\u884c\u5408\u6210\u3002<\/li><li>\u907f\u958b\u591a\u578b\u7684\u9677\u9631\u3002<\/li><\/ul>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%9B%B4%E5%A5%BD%E7%9A%84%E8%AA%9E%E6%B3%95\"><\/span>\u66f4\u597d\u7684\u8a9e\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<p>\u900f\u904e ES6 \u53ef\u4ee5\u4f7f\u7528\u7c21\u6f54\u7684\u8a9e\u6cd5\u5ba3\u544a\uff0c\u7701\u7565 <code>function<\/code>\u3002\u4e26\u4f7f\u7528 <code>Object.setPrototypeOf()<\/code> \u4f86\u9032\u884c\u59d4\u6d3e\u3002<\/p>\n\n\n<p>\u7c21\u6f54\u65b9\u6cd5\u6703\u6839\u64da\u4e0a\u4e0b\u6587\u8a2d\u5b9a\u8a72\u51fd\u5f0f\u7269\u4ef6\u5167\u90e8\u7684 name \u7279\u6027\u3002\u7136\u800c\u5b83\u5011\u4e0d\u6703\u6709\u8a9e\u5f59\u8b58\u5225\u5b57\u4f86\u9032\u884c\u81ea\u6211\u53c3\u8003\u3002<\/p>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%85%A7%E7%9C%81_Introspection\"><\/span><strong>\u5167\u7701 (Introspection)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<p>\u578b\u5225\u5167\u7701\uff1a\u6aa2\u8996\u4e00\u500b\u5be6\u9ad4\u4ee5\u5224\u65b7\u5b83\u662f\u4f55\u7a2e\u7269\u4ef6\uff0c\u4f9d\u64da\u5b83\u88ab\u5275\u5efa\u7684\u65b9\u5f0f\u4f86\u63a8\u7406\u7269\u4ef6\u7684\u7d50\u69cb\u6216\u80fd\u529b\u3002<\/p>\n\n\n<p><code>instanceof<\/code> \u53ea\u662f\u5be6\u9ad4\u8207\u5efa\u69cb\u51fd\u5f0f\u7684 <code>.prototype<\/code> \u662f\u5426\u6709\u95dc\u9023\u3002\u8981\u4f7f\u7528\u5fc5\u9808\u8981\u6709\u4e00\u500b\u51fd\u5f0f\uff0c\u4e26\u4e14\u51fd\u5f0f\u6709\u5c0d\u7269\u4ef6\u7684\u53c3\u8003\u3002<\/p>\n\n\n<p><code>duck typing (\u9d28\u5b50\u8fa8\u578b)<\/code>\uff1a\u5982\u679c\u770b\u8d77\u4f86\u50cf\u9d28\u5b50\uff0c\u53eb\u8072\u4e5f\u50cf\u9d28\u5b50\uff0c\u90a3\u5fc5\u5b9a\u662f\u96bb\u9d28\u5b50\u3002\u56e0\u6b64\u53ef\u4ee5\u5224\u65b7\u8a72\u7269\u4ef6\u6709\u5176\u65b9\u6cd5\uff0c\u5247\u6709\u80fd\u529b\u4f7f\u7528\u8a72\u65b9\u6cd5\u3002\u7136\u800c\uff0c\u53ef\u80fd\u6703\u6709\u4e00\u4e9b\u9677\u9631(ex. ES6 <code>then<\/code>)\u3002<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">if (a1.something) {\n\ta1.something();\n}<\/pre>\n\n\n<p>OLOO \u98a8\u683c\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u4f86\u9032\u884c\u578b\u5225\u5167\u7701\uff0c\u53d6\u4ee3 <code>instanceof<\/code>\u3002<\/p>\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ relating `Foo` and `Bar` to each other\nFoo.isPrototypeOf( Bar ); \/\/ true\nObject.getPrototypeOf( Bar ) === Foo; \/\/ true\n\/\/ relating `b1` to both `Foo` and `Bar`\nFoo.isPrototypeOf( b1 ); \/\/ true\nBar.isPrototypeOf( b1 ); \/\/ true\nObject.getPrototypeOf( b1 ) === Bar; \/\/ true<\/pre>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%A4%87%E7%BF%92\"><\/span><strong>\u8907\u7fd2<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<ul class=\"wp-block-list\"><li>\u884c\u70ba\u59d4\u6d3e\u6a21\u5f0f\u4e2d\uff0c\u7269\u4ef6\u662f\u5f7c\u6b64\u5c0d\u7b49\u7684\u540c\u5115\uff0c\u4e4b\u9593\u6703\u6709\u59d4\u6d3e\u95dc\u4fc2\uff0c\u800c\u975e\u7236\u5b50\u985e\u5225\u95dc\u4fc2\u3002<\/li><li>\u50c5\u4f7f\u7528\u7269\u4ef6\u4f86\u8a2d\u8a08\u7a0b\u5f0f\u78bc\uff0c\u4e0d\u53ea\u7c21\u5316\u4e86\u6240\u4f7f\u7528\u7684\u8a9e\u6cd5\uff0c\u5be6\u969b\u4e0a\u4e5f\u80fd\u7522\u751f\u8f03\u7c21\u55ae\u7684\u67b6\u69cb\u8a2d\u8a08\u3002<\/li><\/ul>\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%99%84%E9%8C%84_D_%E2%80%93_ES6_%E9%A1%9E%E5%88%A5\"><\/span><strong>\u9644\u9304 D\u00a0&#8211;\u00a0ES6\u00a0\u985e\u5225<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n<p>ES6 Class \u8a9e\u6cd5\u7cd6\u512a\u9ede\uff1a<\/p>\n\n\n<ul class=\"wp-block-list\"><li>\u6c92\u6709\u5c0d <code>.prototype<\/code> \u7684\u53c3\u8003\u3002<\/li><li>\u4f7f\u7528 <code>extends<\/code>\u3002<\/li><li><code>super<\/code> \u4f7f\u5f97\u5728\u4e32\u93c8\u67d0\u4e00\u5c64\u7d1a\u90fd\u80fd\u5920\u76f8\u5c0d\u5f80\u4e0a\u53c3\u8003\u540c\u540d\u7684\u65b9\u6cd5\u3002<\/li><li><code>class<\/code> \u9810\u8a2d\u4e0d\u5305\u62ec\u6307\u5b9a\u7279\u6027\uff0c\u9632\u5446\u6a5f\u5236\u3002<\/li><\/ul>\n\n\n<p>\u9677\u9631\uff1a<\/p>\n\n\n<ul class=\"wp-block-list\"><li>\u4f7f\u4eba\u8aa4\u4ee5\u70ba\u771f\u7684\u6709\u985e\u5225\u6a5f\u5236\u3002\u5be6\u969b\u4e0a\u4ecd\u662f\u4f7f\u7528\u59d4\u6d3e\uff0c\u56e0\u6b64\u4fee\u6539\u4e86\u7236\u985e\u5225\u7684\u65b9\u6cd5\u6642\uff0c\u5b50\u985e\u5225\u4e5f\u6703\u53d7\u5f71\u97ff\u3002<\/li><li>\u7576\u9700\u8981\u5ba3\u544a\u7279\u6027\u6642\uff0c\u4ecd\u5f97\u56de\u6b78\u5230\u4f7f\u7528 <code>.prototype<\/code>\uff0c\u4f7f\u5f97\u5be6\u4f5c\u7d30\u7bc0\u66b4\u9732\u3002<\/li><li>\u5b58\u5728\u7279\u6027\u906e\u853d\u554f\u984c\u3002<\/li><li><code>super<\/code> \u662f\u5728\u5ba3\u544a\u6642\u671f\u4ee5\u7b97\u662f\u300c\u975c\u614b\u300d\u7684\u65b9\u5f0f\u7e6b\u7d50\u7684\u3002<\/li><\/ul>\n\n\n<p>\u96d6\u7136 ES6 class \u8a9e\u6cd5\u770b\u4f3c\u6f02\u4eae\uff0c\u4f46\u5be6\u969b\u4e0a\u6703\u4f7f\u5f97\u6982\u5ff5\u66f4\u6a21\u7cca\u4e0d\u6e05\uff0c\u4ee4\u4eba\u4ee5\u70ba\u662f\u975c\u614b\u7684\uff0c\u7136\u800c\u5728 JS \u4e2d\uff0c\u4efb\u4f55\u7269\u4ef6\u7684\u5b9a\u7fa9\u90fd\u662f\u4e00\u7a2e\u6d41\u52d5\u53ef\u8b8a\u7684\u6771\u897f\uff0c\u800c\u9019\u4e5f\u662f JS \u7684\u5f37\u5927\u4e4b\u8655\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8907\u7fd2\u7b2c 10 \u7ae0\uff0c[[Prototype]] \u6a5f\u5236&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[13,12],"tags":[21],"class_list":["post-379","post","type-post","status-publish","format-standard","hentry","category-jsclosuresthis","category-12","tag-javascript"],"_links":{"self":[{"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/posts\/379","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=379"}],"version-history":[{"count":0,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=\/wp\/v2\/posts\/379\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.winter-weng.cc\/work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}