{"id":58,"date":"2021-01-17T19:19:37","date_gmt":"2021-01-17T11:19:37","guid":{"rendered":"http:\/\/gjweb.top\/?p=58"},"modified":"2021-01-17T19:19:38","modified_gmt":"2021-01-17T11:19:38","slug":"%e5%b0%81%e8%a3%85-%e7%bb%a7%e6%89%bf-%e5%a4%9a%e6%80%81","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=58","title":{"rendered":"\u5c01\u88c5 &#038;&#038; \u7ee7\u627f &#038;&#038; \u591a\u6001"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5c01\u88c5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9a\u4e49<\/h3>\n\n\n\n<p>\u8bb2\u4e00\u4e2a\u4e8b\u7269\u7684\u5c5e\u6027\u548c\u529f\u80fd\u96c6\u4e2d\u5728\u4e00\u4e2a\u5bf9\u8c61\u4e2d<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5bf9\u8c61\u7684\u7279\u70b9<\/h3>\n\n\n\n<p>\u5c01\u88c5 \u7ee7\u627f \u591a\u6001<\/p>\n\n\n\n<p>\u5b9a\u4e49<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u63cf\u8ff0\u663e\u793a\u4e2d\u4e00\u4e2a\u4e8b\u7269\u7684\u5c5e\u6027\u548c\u529f\u80fd\u7684\u7a0b\u5e8f\u7ed3\u6784,\u540c\u65f6\u548c\u5b58\u50a8\u4e8b\u7269\u7684\u591a\u4e2a\u5c5e\u6027\u548c\u529f\u80fd\u7684\u50a8\u5b58\u7a7a\u95f4<\/li><li>\u9762\u5411\u5bf9\u8c61<ul><li>\u7a0b\u5e8f\u4e2d\u90fd\u662f\u7528\u5bf9\u8c61\u6765\u63cf\u8ff0\u73b0\u5b9e\u4e2d\u7684\u4e00\u4e2a\u5177\u4f53\u4e8b\u7269<\/li><\/ul><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7ee7\u627f<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b9a\u4e49<ul><li>\u7236\u5bf9\u8c61\u7684\u6210\u5458,\u5b50\u5bf9\u8c61\u65e0\u9700\u91cd\u590d\u521b\u5efa\u5c31\u53ef\u76f4\u63a5\u4f7f\u7528<\/li><\/ul><\/li><li>\u4f18\u70b9<ul><li>\u4ee3\u7801\u91cd\u7528,\u8282\u7ea6\u5185\u5b58<\/li><\/ul><\/li><li>\u7528\u5904<ul><li>\u53ea\u8981\u591a\u4e2a\u5b50\u5bf9\u8c61,\u62e5\u6709\u76f8\u540c\u7684\u5c5e\u6027\u548c\u7a7a\u80fd,\u90fd\u8981\u5c06\u76f8\u540c\u7684\u5c5e\u6027\u548c\u529f\u80fd\u96c6\u4e2d\u4fdd\u5b58\u5728\u7236\u5bf9\u8c61\u4e2d,\u6240\u6709\u5b50\u5bf9\u8c61\u516c\u7528<\/li><\/ul><\/li><li>\u539f\u578b<ul><li>js\u4e2d\u7ee7\u627f\u90fd\u662f <strong>\u7ee7\u627f\u539f\u578b\u5bf9\u8c61<\/strong><ul><li>\u5b9a\u4e49<ul><li>\u4e13\u95e8\u96c6\u4e2d\u50a8\u5b58\u4e00\u7c7b\u5b50\u5bf9\u8c61\u76f8\u540c\u5c5e\u6027\u503c\u548c\u65b9\u6cd5\u7684\u7236\u5bf9\u8c61<\/li><\/ul><\/li><li>\u7528\u5904<ul><li>\u53ea\u8981\u5b50\u5bf9\u8c61\u516c\u7528\u7684\u76f8\u540c\u5c5e\u6027\u90fd\u8981\u653e\u5728\u539f\u578b\u5bf9\u8c61\u4e2d<\/li><\/ul><\/li><li>\u5982\u4f55\u7528<ul><li>\u6bcf\u521b\u5efa\u4e00\u4e2a\u6784\u9020\u51fd\u6570,\u90fd\u4f1a\u81ea\u52a8\u51fa\u73b0\u4e00\u4e2a\u539f\u578b\u5bf9\u8c61\u7684 <strong>proto<\/strong> \u7ee7\u627f\u6784\u9020\u51fd\u6570\u7684prototype<\/li><\/ul><\/li><li>\u5982\u4f55\u5411\u539f\u578b\u4e2d\u6dfb\u52a0\u516c\u7528\u5c5e\u6027<\/li><\/ul><\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6784\u9020\u6784\u9020\u51fd\u6570.prototype.\u5c5e\u6027\u540d = \u5c5e\u6027\u503c\r\n\u6784\u9020\u51fd\u6570.prototype.\u5c5e\u6027\u540d = function(){}\n<\/code><\/pre>\n\n\n\n<p>\u9274\u522b\u5c5e\u6027\u662f\u81ea\u6709\u8fd8\u662f\u5171\u6709<\/p>\n\n\n\n<p>\u81ea\u6709<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var bool = obj.hasOwnProperty(\"\u5c5e\u6027\u540d\")<\/code><\/pre>\n\n\n\n<p>\u5171\u6709<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5c5e\u6027\u540d in obj<\/code><\/pre>\n\n\n\n<p>\u56fa\u5b9a\u5957\u8def<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function jubge(val,obj){\r\n    if(obj.hasOwnProperty(value)){\r\n        console.log(\"\u81ea\u6709\")\r\n    }else if(var in obj != undefined){\r\n        console.log(\"\u5171\u6709\")\r\n    }else{\r\n        console.log(\"\u6ca1\u6709\")\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u539f\u578b\u94fe<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b9a\u4e49<ul><li>\u6709\u591a\u7ea7\u7236\u5143\u7d20\u9010\u6e10\u7ee7\u627f\u5f62\u6210\u7684\u94fe\u5f0f\u7ed3\u6784<\/li><li>\u4fdd\u5b58\u7740\u6240\u6709\u5bf9\u8c61\u6210\u5458(\u5c5e\u6027\u548c\u65b9\u6cd5)<\/li><li>vs \u4f5c\u7528\u57df<ul><li>\u4fdd\u5b58\u7740\u6240\u6709\u53d8\u91cf<\/li><\/ul><\/li><li>\u63a7\u5236\u7740 \u5bf9\u8c61\u6210\u5458\u7684\u4f7f\u7528\u987a\u5e8f<\/li><li>\u6709\u9650\u4f7f\u7528\u81ea\u5df1,\u81ea\u5df1\u6ca1\u6709\u6cbf\u539f\u578b\u94fe\u5411\u7236\u7ea7\u67e5\u627e<\/li><li>\u539f\u578b\u94fe\u7684\u9876\u7aef\u662f<strong>object.prototype<\/strong><\/li><li>vs \u4f5c\u7528\u57df\u7684\u91cd\u70b9\u662fwindow<\/li><\/ul><\/li><li>\u9a8c\u8bc1\u539f\u578b\u5bf9\u8c61<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ 1. Object.getprototypeOf(obj)\r\nObject.getprototpyeOf(obj)==Array\r\n\/\/ 2. \u83b7\u53d6father\u7684\u5b50\u5bf9\u8c61\u662f\u5426\u662fchild\r\nvar a = father.isprototype(child);\r\n\/\/ 3. \u9a8c\u8bc1\u6784\u9020\u51fd\u6570\u662f\u5426\u662f\u6570\u7ec4\u7c7b\u578b\r\nobj.constructor==Array\r\n\/\/ 4. \u5373\u4f7f\u521b\u5efa\u65f6\u4e0d\u662f\u4f7f\u7528\u6570\u7ec4\u521b\u5efa\u7684,\u4f46\u662f\u53ea\u8981\u539f\u578b\u94fe\u4e0a\u6709\u6570\u7ec4\u7c7b\u578b\u4e5f\u4f1a\u88ab\u8ba4\u4e3a\u662f\u6570\u7ec4\u7c7b\u578b\r\nobj instanceof Array\r\n\/\/ 5. isArray()\r\n\/\/ \u6bcf\u4e2a\u5b50\u5bf9\u8c61\u4e2d\u521b\u5efa\u4f7f\u7528\u7684\u7c7b\u578b\u5c5e\u6027\u4e00\u65e6\u88ab\u521b\u5efa.class\u5c5e\u6027\u5c31\u65e0\u6cd5\u4fee\u6539; \u51e0\u4e4e\u6240\u6709\u5185\u7f6e\u5bf9\u8c61\u90fd\u91cd\u5199\u4e86toString,\u65e0\u6cd5\u83b7\u5f97Object.toString()\r\n\/\/\u89e3\u51b3 call \/\/\u4efb\u610f\u5bf9\u8c61.\u4efb\u610f\u65b9\u6cd5 call(obj)\r\n\/\/ 6. Object.prototype.toString\r\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u591a\u6001<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u7edf\u4e00\u4e8b\u7269\u5728\u4e0d\u540c\u60c5\u51b5\u4e0b\u8868\u73b0\u51fa\u4e0d\u540c\u7684\u72b6\u6001<\/li><li>\u91cd\u5199 <strong>override<\/strong><ul><li>\u5982\u679c\u7236\u539f\u578b\u7684\u65b9\u6cd5\u4e0d\u597d\u7528\u53ef\u4ee5\u91cd\u5199\u5b50\u5bf9\u8c61\u7684\u65b9\u6cd5<\/li><\/ul><\/li><li>\u81ea\u5b9a\u4e49\u7ee7\u627f<ul><li>\u8bbe\u7f6e\u4e24\u4e2a\u5bf9\u8c61\u5efa\u7684\u7ee7\u627f\u5173\u7cfb<\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>child.__proto___ = father\r\n\/*\r\n\t\u95ee\u9898\r\n\t\t__proto__\u4e5f\u662f\u5185\u90e8\u5c5e\u6027\u3002\u6709\u53ef\u80fd\u88ab\u6d4f\u89c8\u5668\u7981\u7528\r\n\t\u89e3\u51b3:\r\n\t\tObject.setPrototypeOf(child,father);\r\n\t\t\u8bbe\u7f6echild\u7ee7\u627ffather\r\n*\/<\/code><\/pre>\n\n\n\n<p>\u6279\u91cf\u4fee\u6539\u591a\u4e2a\u5bf9\u8c61\u7684\u7ee7\u627f\u5173\u7cfb<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u53ea\u8981\u4fee\u6539\u6784\u9020\u51fd\u6570\u7684prototype\u5bf9\u8c61\u5373\u53ef<\/li><li>\u7528\u6cd5<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6784\u9020\u51fd\u6570prototype = father<\/code><\/pre>\n\n\n\n<p>\u65f6\u673a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b9a\u4e49\u5b8c\u6784\u9020\u51fd\u6570\u4e4b\u540e\uff0c\u7acb\u523b\u4fee\u6539\u539f\u578b\u5bf9\u8c61<\/li><\/ul>\n\n\n\n<p>\u4e24\u79cd\u7c7b\u578b\u95f4\u7684\u7ee7\u627f<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f55\u65f6<ul><li>\u5982\u679c\u53d1\u73b0\u591a\u4e2a\u7c7b\u578b\u4e4b\u95f4\u62e5\u6709\u76f8\u540c\u7684\u5c5e\u6027\u89e3\u6784\u548c\u65b9\u6cd5\u65f6\u5c31\u8981\u62bd\u8c61\u4e00\u4e2a\u7236\u7c7b\u578b<\/li><\/ul><\/li><li>\u6b65\u9aa4<ul><li>\u5b9a\u4e49\u7236\u7c7b\u578b<ul><li>\u7236\u7c7b\u578b\u7684\u6784\u9020\u7b80\u4e66,\u96c6\u4e2d\u5b9a\u4e49\u76f8\u540c\u7684\u5c5e\u6027\u7ed3\u6784<\/li><li>\u7236\u7c7b\u578b\u7684\u539f\u578b\u5bf9\u8c61,\u96c6\u4e2d\u5b9a\u4e49\u76f8\u540c\u7684\u65b9\u6cd5<\/li><\/ul><\/li><li>\u8ba9\u5b50\u7c7b\u578b\u7684\u539f\u578b\u5bf9\u8c61\u7ee7\u627f\u7236\u7c7b\u578b\u539f\u578b\u5bf9\u8c61<ul><li>\u7ed3\u679c<ul><li>\u4fdd\u8bc1\u5b50\u5bf9\u8c61\u53ef\u8c03\u7528\u62bd\u8c61\u7236\u7c7b\u578b\u539f\u578b\u4e2d\u7684\u65b9\u6cd5<\/li><\/ul><\/li><\/ul><\/li><li>\u5728\u5b50\u7c7b\u578b\u6784\u9020\u51fd\u6570\u4e2d\u501f\u7528\u7236\u7c7b\u578b\u6784\u9020\u51fd\u6570<ul><li>\u7ed3\u679c<ul><li>\u8bf7\u7236\u7c7b\u578b\u6784\u9020\u51fd\u6570\u5e2e\u52a9\u6784\u5efa\u5171\u6709\u7684\u5c5e\u6027\u7ed3\u6784<\/li><\/ul><\/li><\/ul><\/li><\/ul><\/li><li>\u95ee\u9898<ul><li>\u76f4\u63a5\u8c03\u7528\u7236\u7c7b\u578b\u6784\u9020\u51fd\u6570,\u5176\u4e2d<strong>this<\/strong>\u9ed8\u8ba4\u6307\u5411<strong>window<\/strong><\/li><li>\u89e3\u51b3<ul><li>call \/\/ \u53ea\u8981this\u4e0d\u8981\u60f3\u8981\u7684,\u5c31\u53ef\u7528call\u968f\u4fbf\u66ff\u6362<\/li><\/ul><\/li><\/ul><\/li><li>\u7528\u6cd5<ul><li>\u7236\u7c7b\u578b\u6784\u9020\u51fd\u6570 <strong>.call(this,\u53c2\u6570&#8230;)<\/strong><\/li><\/ul><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>function Flyer(name,speed){\r\n    this.name = name;\r\n    this.speed = speed\r\n}\r\nFlyer.prototype.fly = function(){\r\n    console.log(`${this.name}\u4ee5\u65f6\u901f${this.speed}\u98de\u884c`)\r\n}\r\nfunction Plane(name,speed,score){\r\n    Flyer.call(this,name,speed);\r\n    this.scper = score\r\n}\r\nPlane.prototype.getScore = function(){\r\n    console.log(`\u51fb\u843d${this.name}\u7684${this.score}`)\r\n}\r\nObject.setPrototypeOf(Plane.prototype,Flyer.prototype);\r\nvar a = new Plane(\"f16\",\"10000\",20);\r\na.fly();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5c01\u88c5 \u5b9a\u4e49 \u8bb2\u4e00\u4e2a\u4e8b\u7269\u7684\u5c5e\u6027\u548c\u529f\u80fd\u96c6\u4e2d\u5728\u4e00\u4e2a\u5bf9\u8c61\u4e2d \u5bf9\u8c61\u7684\u7279\u70b9 \u5c01\u88c5 \u7ee7\u627f \u591a\u6001 \u5b9a\u4e49 \u63cf\u8ff0\u663e\u793a\u4e2d\u4e00\u4e2a\u4e8b\u7269\u7684\u5c5e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-58","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/58","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=58"}],"version-history":[{"count":0,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/58\/revisions"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}