{"id":29370,"date":"2024-11-25T10:11:44","date_gmt":"2024-11-25T02:11:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29370\/"},"modified":"2024-11-25T10:11:44","modified_gmt":"2024-11-25T02:11:44","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%883%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29370\/","title":{"rendered":"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09"},"content":{"rendered":"<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Class(\u7c7b)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Class\u662fES6\u5f15\u5165\u7684\u6700\u91cd\u8981\u7279\u6027\u4e4b\u4e00\u3002\u5728\u6ca1\u6709Class\u4e4b\u524d\uff0c\u6211\u4eec\u53ea\u80fd\u901a\u8fc7\u539f\u578b\u94fe\u6765\u6a21\u62df\u7c7b\u3002<\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Class Definition(\u7c7b\u7684\u5b9a\u4e49)<\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3bfa74a572b6d5d11913fba6f0ebb2fd-0.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe\" \/><\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u4e0a\u9762\u5b9a\u4e49\u4e86\u4e00\u4e2aShape\u7c7b\uff0c\u4ed6\u6709\u4e00\u4e2a\u5c5e\u6027 name \u548c\u4e00\u4e2a\u65b9\u6cd5 move()\uff0c\u8fd8\u6709\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u3002<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u8c03\u7528Shape\u7c7b<\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3bfa74a572b6d5d11913fba6f0ebb2fd-1.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe1\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe1\" \/><br \/><\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Class Inheritance(\u7c7b\u7684\u7ee7\u627f)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u901a\u8fc7\u5173\u952e\u5b57 extends \u6765\u7ee7\u627f\u4e00\u4e2a\u7c7b\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7 super \u5173\u952e\u5b57\u6765\u5f15\u7528\u7236\u7c7b\u3002<\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/3bfa74a572b6d5d11913fba6f0ebb2fd-2.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe2\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe2\" \/><br \/><\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u8c03\u7528Rectangle\u3001Circle\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\/2555358d7cc3d9ef74dd8d1cbb3f7d33-3.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe3\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe3\" \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"line-height:2em\">Getter\/Setter<\/span><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><br \/><\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u5728Class\u5185\u90e8\u53ef\u4ee5\u4f7f\u7528get\u548cset\u5173\u952e\u5b57\uff0c\u5bf9\u67d0\u4e2a\u5c5e\u6027\u8bbe\u7f6e\u5b58\u503c\u51fd\u6570\u548c\u53d6\u503c\u51fd\u6570\uff0c\u62e6\u622a\u8be5\u5c5e\u6027\u7684\u5b58\u53d6\u884c\u4e3a\u3002<\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/2555358d7cc3d9ef74dd8d1cbb3f7d33-4.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe4\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe4\" \/><br \/><\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">Static Members(\u9759\u6001\u6210\u5458)<\/span><\/p>\n<p style=\"line-height:2em\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u7c7b\u76f8\u5f53\u4e8e\u5b9e\u4f8b\u7684\u539f\u578b\uff0c\u6240\u6709\u5728\u7c7b\u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5\uff0c\u90fd\u4f1a\u88ab\u5b9e\u4f8b\u7ee7\u627f\u3002\u5982\u679c\u5728\u4e00\u4e2a\u65b9\u6cd5\u524d\uff0c\u52a0\u4e0astatic\u5173\u952e\u5b57\uff0c\u5c31\u8868\u793a\u8be5\u65b9\u6cd5\u4e0d\u4f1a\u88ab\u5b9e\u4f8b\u7ee7\u627f\uff0c\u800c\u662f\u76f4\u63a5\u901a\u8fc7\u7c7b\u6765\u8c03\u7528\uff0c\u8fd9\u5c31\u79f0\u4e3a\u201c\u9759\u6001\u65b9\u6cd5\u201d\u3002<\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/010\/2555358d7cc3d9ef74dd8d1cbb3f7d33-5.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe5\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe5\" \/><br \/><\/span><\/p>\n<p style=\"line-height:normal\"><span style=\"font-family:\u5fae\u8f6f\u96c5\u9ed1,\">\u9759\u6001\u5c5e\u6027\u6307\u7684\u662fClass\u672c\u8eab\u7684\u5c5e\u6027\uff0c\u5373Class.propname\uff0c\u800c\u4e0d\u662f\u5b9a\u4e49\u5728\u5b9e\u4f8b\u5bf9\u8c61(this)\u4e0a\u7684\u5c5e\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\/2555358d7cc3d9ef74dd8d1cbb3f7d33-6.jpg\" class=\"aligncenter\" title=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe6\" alt=\"ES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\uff09\u63d2\u56fe6\" \/><br \/><\/span><\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\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>Class(\u7c7b) Class\u662fES6\u5f15\u5165\u7684\u6700\u91cd\u8981\u7279\u6027\u4e4b\u4e00\u3002\u5728\u6ca1\u6709Class\u4e4b\u524d\uff0c\u6211\u4eec\u53ea\u80fd\u901a\u8fc7\u539f\u578b\u94fe\u6765\u6a21\u62df\u7c7b\u3002 Class Definition(\u7c7b\u7684\u5b9a\u4e49) \u4e0a\u9762\u5b9a\u4e49\u4e86\u4e00\u4e2aShape\u7c7b\uff0c\u4ed6\u6709\u4e00\u4e2a\u5c5e\u6027 name \u548c\u4e00\u4e2a\u65b9\u6cd5 move()\uff0c\u8fd8\u6709\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u3002 \u8c03\u7528Shape\u7c7b Class Inheritance(\u7c7b\u7684\u7ee7\u627f) \u901a\u8fc7\u5173\u952e\u5b57 extends \u6765\u7ee7\u627f\u4e00\u4e2a\u7c7b\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7 super \u5173\u952e\u5b57\u6765\u5f15\u7528\u7236\u7c7b\u3002 \u8c03\u7528Rectangle\u3001Circle\u7c7b Getter\/Setter \u5728Class\u5185\u90e8\u53ef\u4ee5\u4f7f\u7528get\u548cset\u5173\u952e\u5b57\uff0c\u5bf9\u67d0\u4e2a\u5c5e\u6027\u8bbe\u7f6e\u5b58\u503c\u51fd\u6570\u548c\u53d6\u503c\u51fd\u6570\uff0c\u62e6\u622a\u8be5\u5c5e\u6027\u7684\u5b58\u53d6\u884c\u4e3a\u3002 Static Members(\u9759\u6001\u6210\u5458) \u7c7b\u76f8\u5f53\u4e8e\u5b9e\u4f8b\u7684\u539f\u578b\uff0c\u6240\u6709\u5728\u7c7b\u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5\uff0c\u90fd\u4f1a\u88ab\u5b9e\u4f8b\u7ee7\u627f\u3002\u5982\u679c\u5728\u4e00\u4e2a\u65b9\u6cd5\u524d\uff0c\u52a0\u4e0astatic\u5173\u952e\u5b57\uff0c\u5c31\u8868\u793a\u8be5\u65b9\u6cd5\u4e0d\u4f1a\u88ab\u5b9e\u4f8b\u7ee7\u627f\uff0c\u800c\u662f\u76f4\u63a5\u901a\u8fc7\u7c7b\u6765\u8c03\u7528\uff0c\u8fd9\u5c31\u79f0\u4e3a\u201c\u9759\u6001\u65b9\u6cd5\u201d\u3002 \u9759\u6001\u5c5e\u6027\u6307\u7684\u662fClass\u672c\u8eab\u7684\u5c5e\u6027\uff0c\u5373Class.propname\uff0c\u800c\u4e0d\u662f\u5b9a\u4e49\u5728\u5b9e\u4f8b\u5bf9\u8c61(this)\u4e0a\u7684\u5c5e\u6027 \u4ee5\u4e0a\u5c31\u662fES6\u65b0\u7279\u6027\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff083\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-29370","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29370","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=29370"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29370\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}