{"id":326,"date":"2020-02-04T22:15:05","date_gmt":"2020-02-04T14:15:05","guid":{"rendered":"https:\/\/blog.cqdefxxx.com\/?p=326"},"modified":"2020-02-04T22:15:05","modified_gmt":"2020-02-04T14:15:05","slug":"%e5%8e%9f%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/blog.viter.top\/index.php\/2020\/02\/04\/%e5%8e%9f%e5%9e%8b\/","title":{"rendered":"\u539f\u578b"},"content":{"rendered":"<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;meta charset=\"UTF-8\"&gt;\n\t\t&lt;title&gt;&lt;\/title&gt;\n\t\t&lt;script type=\"text\/javascript\"&gt;\n\t\t\t\/*\n\t\t\t * \u539f\u578b prototype\n\t\t\t * \n\t\t\t * \t\u6211\u4eec\u6240\u521b\u5efa\u7684\u6bcf\u4e00\u4e2a\u51fd\u6570\uff0c\u89e3\u6790\u5668\u90fd\u4f1a\u5411\u51fd\u6570\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u5c5e\u6027prototype\n\t\t\t * \t\t\u8fd9\u4e2a\u5c5e\u6027\u5bf9\u5e94\u7740\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8fd9\u4e2a\u5bf9\u8c61\u5c31\u662f\u6211\u4eec\u6240\u8c13\u7684\u539f\u578b\u5bf9\u8c61\n\t\t\t * \t\u5982\u679c\u51fd\u6570\u4f5c\u4e3a\u666e\u901a\u51fd\u6570\u8c03\u7528prototype\u6ca1\u6709\u4efb\u4f55\u4f5c\u7528\n\t\t\t * \t\u5f53\u51fd\u6570\u4ee5\u6784\u9020\u51fd\u6570\u7684\u5f62\u5f0f\u8c03\u7528\u65f6\uff0c\u5b83\u6240\u521b\u5efa\u7684\u5bf9\u8c61\u4e2d\u90fd\u4f1a\u6709\u4e00\u4e2a\u9690\u542b\u7684\u5c5e\u6027\uff0c\n\t\t\t * \t\t\u6307\u5411\u8be5\u6784\u9020\u51fd\u6570\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7__proto__\u6765\u8bbf\u95ee\u8be5\u5c5e\u6027\n\t\t\t * \n\t\t\t * \t\u539f\u578b\u5bf9\u8c61\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u516c\u5171\u7684\u533a\u57df\uff0c\u6240\u6709\u540c\u4e00\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u90fd\u53ef\u4ee5\u8bbf\u95ee\u5230\u8fd9\u4e2a\u539f\u578b\u5bf9\u8c61\uff0c\n\t\t\t * \t\t\u6211\u4eec\u53ef\u4ee5\u5c06\u5bf9\u8c61\u4e2d\u5171\u6709\u7684\u5185\u5bb9\uff0c\u7edf\u4e00\u8bbe\u7f6e\u5230\u539f\u578b\u5bf9\u8c61\u4e2d\u3002\n\t\t\t * \n\t\t\t * \u5f53\u6211\u4eec\u8bbf\u95ee\u5bf9\u8c61\u7684\u4e00\u4e2a\u5c5e\u6027\u6216\u65b9\u6cd5\u65f6\uff0c\u5b83\u4f1a\u5148\u5728\u5bf9\u8c61\u81ea\u8eab\u4e2d\u5bfb\u627e\uff0c\u5982\u679c\u6709\u5219\u76f4\u63a5\u4f7f\u7528\uff0c\n\t\t\t * \t\u5982\u679c\u6ca1\u6709\u5219\u4f1a\u53bb\u539f\u578b\u5bf9\u8c61\u4e2d\u5bfb\u627e\uff0c\u5982\u679c\u627e\u5230\u5219\u76f4\u63a5\u4f7f\u7528\n\t\t\t * \n\t\t\t * \u4ee5\u540e\u6211\u4eec\u521b\u5efa\u6784\u9020\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u5bf9\u8c61\u5171\u6709\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u7edf\u4e00\u6dfb\u52a0\u5230\u6784\u9020\u51fd\u6570\u7684\u539f\u578b\u5bf9\u8c61\u4e2d\uff0c\n\t\t\t * \t\u8fd9\u6837\u4e0d\u7528\u5206\u522b\u4e3a\u6bcf\u4e00\u4e2a\u5bf9\u8c61\u6dfb\u52a0\uff0c\u4e5f\u4e0d\u4f1a\u5f71\u54cd\u5230\u5168\u5c40\u4f5c\u7528\u57df\uff0c\u5c31\u53ef\u4ee5\u4f7f\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u5177\u6709\u8fd9\u4e9b\u5c5e\u6027\u548c\u65b9\u6cd5\u4e86\n\t\t\t *\/\n\t\t\t\n\t\t\tfunction MyClass(){\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\t\/\/\u5411MyClass\u7684\u539f\u578b\u4e2d\u6dfb\u52a0\u5c5e\u6027a\n\t\t\tMyClass.prototype.a = 123;\n\t\t\t\n\t\t\t\/\/\u5411MyClass\u7684\u539f\u578b\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b9\u6cd5\n\t\t\tMyClass.prototype.sayHello = function(){\n\t\t\t\talert(\"hello\");\n\t\t\t};\n\t\t\t\n\t\t\tvar mc = new MyClass();\n\t\t\t\n\t\t\tvar mc2 = new MyClass();\n\t\t\t\n\t\t\t\/\/console.log(MyClass.prototype);\n\t\t\t\/\/console.log(mc2.__proto__ == MyClass.prototype);\n\t\t\t\n\t\t\t\/\/\u5411mc\u4e2d\u6dfb\u52a0a\u5c5e\u6027\n\t\t\tmc.a = \"\u6211\u662fmc\u4e2d\u7684a\";\n\t\t\t\n\t\t\t\/\/console.log(mc2.a);\n\t\t\t\n\t\t\tmc.sayHello();\n\t\t\t\n\t\t\t\n\t\t&lt;\/script&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;meta charset=\"UTF-8\"&gt;\n\t\t&lt;title&gt;&lt;\/title&gt;\n\t\t&lt;script type=\"text\/javascript\"&gt;\n\t\t\t\n\t\t\t\/*\n\t\t\t * \u521b\u5efa\u4e00\u4e2a\u6784\u9020\u51fd\u6570\n\t\t\t *\/\n\t\t\tfunction MyClass(){\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\t\/\/\u5411MyClass\u7684\u539f\u578b\u4e2d\u6dfb\u52a0\u4e00\u4e2aname\u5c5e\u6027\n\t\t\tMyClass.prototype.name = \"\u6211\u662f\u539f\u578b\u4e2d\u7684\u540d\u5b57\";\n\t\t\t\n\t\t\tvar mc = new MyClass();\n\t\t\tmc.age = 18;\n\t\t\t\n\t\t\t\/\/console.log(mc.name);\n\t\t\t\n\t\t\t\/\/\u4f7f\u7528in\u68c0\u67e5\u5bf9\u8c61\u4e2d\u662f\u5426\u542b\u6709\u67d0\u4e2a\u5c5e\u6027\u65f6\uff0c\u5982\u679c\u5bf9\u8c61\u4e2d\u6ca1\u6709\u4f46\u662f\u539f\u578b\u4e2d\u6709\uff0c\u4e5f\u4f1a\u8fd4\u56detrue\n\t\t\t\/\/console.log(\"name\" in mc);\n\t\t\t\n\t\t\t\/\/\u53ef\u4ee5\u4f7f\u7528\u5bf9\u8c61\u7684hasOwnProperty()\u6765\u68c0\u67e5\u5bf9\u8c61\u81ea\u8eab\u4e2d\u662f\u5426\u542b\u6709\u8be5\u5c5e\u6027\n\t\t\t\/\/\u4f7f\u7528\u8be5\u65b9\u6cd5\u53ea\u6709\u5f53\u5bf9\u8c61\u81ea\u8eab\u4e2d\u542b\u6709\u5c5e\u6027\u65f6\uff0c\u624d\u4f1a\u8fd4\u56detrue\n\t\t\t\/\/console.log(mc.hasOwnProperty(\"age\"));\n\t\t\t\n\t\t\t\/\/console.log(mc.hasOwnProperty(\"hasOwnProperty\"));\n\t\t\t\n\t\t\t\/*\n\t\t\t * \u539f\u578b\u5bf9\u8c61\u4e5f\u662f\u5bf9\u8c61\uff0c\u6240\u4ee5\u5b83\u4e5f\u6709\u539f\u578b\uff0c\n\t\t\t * \t\u5f53\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\u65f6\uff0c\u4f1a\u73b0\u5728\u81ea\u8eab\u4e2d\u5bfb\u627e\uff0c\n\t\t\t * \t\t\u81ea\u8eab\u4e2d\u5982\u679c\u6709\uff0c\u5219\u76f4\u63a5\u4f7f\u7528\uff0c\n\t\t\t * \t\t\u5982\u679c\u6ca1\u6709\u5219\u53bb\u539f\u578b\u5bf9\u8c61\u4e2d\u5bfb\u627e\uff0c\u5982\u679c\u539f\u578b\u5bf9\u8c61\u4e2d\u6709\uff0c\u5219\u4f7f\u7528\uff0c\n\t\t\t * \t\t\u5982\u679c\u6ca1\u6709\u5219\u53bb\u539f\u578b\u7684\u539f\u578b\u4e2d\u5bfb\u627e,\u76f4\u5230\u627e\u5230Object\u5bf9\u8c61\u7684\u539f\u578b\uff0c\n\t\t\t * \t\tObject\u5bf9\u8c61\u7684\u539f\u578b\u6ca1\u6709\u539f\u578b\uff0c\u5982\u679c\u5728Object\u539f\u578b\u4e2d\u4f9d\u7136\u6ca1\u6709\u627e\u5230\uff0c\u5219\u8fd4\u56deundefined\n\t\t\t *\/\n\t\t\t\n\t\t\t\/\/console.log(mc.__proto__.hasOwnProperty(\"hasOwnProperty\"));\n\t\t\t\n\t\t\t\/\/console.log(mc.__proto__.__proto__.hasOwnProperty(\"hasOwnProperty\"));\n\t\t\t\n\t\t\t\/\/console.log(mc.__proto__.__proto__.__proto__);\n\t\t\t\n\t\t\t\/\/console.log(mc.hello);\n\t\t\t\n\t\t\t\/\/console.log(mc.__proto__.__proto__.__proto__)\n\t\t\t\n\t\t&lt;\/script&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset= &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[4],"_links":{"self":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/326"}],"collection":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/comments?post=326"}],"version-history":[{"count":0,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/326\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/media?parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/categories?post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/tags?post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}