{"id":322,"date":"2020-02-04T21:24:16","date_gmt":"2020-02-04T13:24:16","guid":{"rendered":"https:\/\/blog.cqdefxxx.com\/?p=322"},"modified":"2020-02-04T21:24:16","modified_gmt":"2020-02-04T13:24:16","slug":"%e6%9e%84%e9%80%a0%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/blog.viter.top\/index.php\/2020\/02\/04\/%e6%9e%84%e9%80%a0%e5%87%bd%e6%95%b0\/","title":{"rendered":"\u6784\u9020\u51fd\u6570"},"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\n\t\t\t\/*\n\t\t\t * \u521b\u5efa\u4e00\u4e2a\u6784\u9020\u51fd\u6570\uff0c\u4e13\u95e8\u7528\u6765\u521b\u5efaPerson\u5bf9\u8c61\u7684\n\t\t\t * \t\u6784\u9020\u51fd\u6570\u5c31\u662f\u4e00\u4e2a\u666e\u901a\u7684\u51fd\u6570\uff0c\u521b\u5efa\u65b9\u5f0f\u548c\u666e\u901a\u51fd\u6570\u6ca1\u6709\u533a\u522b,\n\t\t\t * \t\u4e0d\u540c\u7684\u662f\u6784\u9020\u51fd\u6570\u4e60\u60ef\u4e0a\u9996\u5b57\u6bcd\u5927\u5199\n\t\t\t * \n\t\t\t * \u6784\u9020\u51fd\u6570\u548c\u666e\u901a\u51fd\u6570\u7684\u533a\u522b\u5c31\u662f\u8c03\u7528\u65b9\u5f0f\u7684\u4e0d\u540c\n\t\t\t * \t\u666e\u901a\u51fd\u6570\u662f\u76f4\u63a5\u8c03\u7528\uff0c\u800c\u6784\u9020\u51fd\u6570\u9700\u8981\u4f7f\u7528new\u5173\u952e\u5b57\u6765\u8c03\u7528\n\t\t\t * \n\t\t\t * \u6784\u9020\u51fd\u6570\u7684\u6267\u884c\u6d41\u7a0b\uff1a\n\t\t\t * \t1.\u7acb\u523b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61\n\t\t\t * \t2.\u5c06\u65b0\u5efa\u7684\u5bf9\u8c61\u8bbe\u7f6e\u4e3a\u51fd\u6570\u4e2dthis,\u5728\u6784\u9020\u51fd\u6570\u4e2d\u53ef\u4ee5\u4f7f\u7528this\u6765\u5f15\u7528\u65b0\u5efa\u7684\u5bf9\u8c61\n\t\t\t * \t3.\u9010\u884c\u6267\u884c\u51fd\u6570\u4e2d\u7684\u4ee3\u7801\n\t\t\t * \t4.\u5c06\u65b0\u5efa\u7684\u5bf9\u8c61\u4f5c\u4e3a\u8fd4\u56de\u503c\u8fd4\u56de\n\t\t\t * \n\t\t\t * \u4f7f\u7528\u540c\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u521b\u5efa\u7684\u5bf9\u8c61\uff0c\u6211\u4eec\u79f0\u4e3a\u4e00\u7c7b\u5bf9\u8c61\uff0c\u4e5f\u5c06\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u79f0\u4e3a\u4e00\u4e2a\u7c7b\u3002\n\t\t\t * \t\u6211\u4eec\u5c06\u901a\u8fc7\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u521b\u5efa\u7684\u5bf9\u8c61\uff0c\u79f0\u4e3a\u662f\u8be5\u7c7b\u7684\u5b9e\u4f8b\n\t\t\t * \n\t\t\t * this\u7684\u60c5\u51b5\uff1a\n\t\t\t * \t1.\u5f53\u4ee5\u51fd\u6570\u7684\u5f62\u5f0f\u8c03\u7528\u65f6\uff0cthis\u662fwindow\n\t\t\t * \t2.\u5f53\u4ee5\u65b9\u6cd5\u7684\u5f62\u5f0f\u8c03\u7528\u65f6\uff0c\u8c01\u8c03\u7528\u65b9\u6cd5this\u5c31\u662f\u8c01\n\t\t\t * \t3.\u5f53\u4ee5\u6784\u9020\u51fd\u6570\u7684\u5f62\u5f0f\u8c03\u7528\u65f6\uff0cthis\u5c31\u662f\u65b0\u521b\u5efa\u7684\u90a3\u4e2a\u5bf9\u8c61\n\t\t\t * \n\t\t\t *\/\n\t\t\tfunction Person(name , age , gender){\n\t\t\t\tthis.name = name;\n\t\t\t\tthis.age = age;\n\t\t\t\tthis.gender = gender;\n\t\t\t\tthis.sayName = function(){\n\t\t\t\t\talert(this.name);\n\t\t\t\t};\n\t\t\t}\n\t\t\t\n\t\t\tfunction Dog(){\n\t\t\t\t\n\t\t\t}\n\t\t\t\n\t\t\tvar per = new Person(\"\u5b59\u609f\u7a7a\",18,\"\u7537\");\n\t\t\tvar per2 = new Person(\"\u7389\u5154\u7cbe\",16,\"\u5973\");\n\t\t\tvar per3 = new Person(\"\u5954\u6ce2\u9738\",38,\"\u7537\");\n\t\t\t\n\t\t\tvar dog = new Dog();\n\t\t\t\n\t\t\t\/*console.log(per);\n\t\t\tconsole.log(dog);*\/\n\t\t\t\n\t\t\t\/*\n\t\t\t * \u4f7f\u7528instanceof\u53ef\u4ee5\u68c0\u67e5\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u662f\u4e00\u4e2a\u7c7b\u7684\u5b9e\u4f8b\n\t\t\t * \t\u8bed\u6cd5\uff1a\n\t\t\t * \t\t\u5bf9\u8c61 instanceof \u6784\u9020\u51fd\u6570\n\t\t\t * \u5982\u679c\u662f\uff0c\u5219\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\n\t\t\t *\/\n\t\t\t\/\/console.log(per instanceof Person);\n\t\t\t\/\/console.log(dog instanceof Person);\n\t\t\t\n\t\t\t\/*\n\t\t\t * \u6240\u6709\u7684\u5bf9\u8c61\u90fd\u662fObject\u7684\u540e\u4ee3\uff0c\n\t\t\t * \t\u6240\u4ee5\u4efb\u4f55\u5bf9\u8c61\u548cObject\u5de6instanceof\u68c0\u67e5\u65f6\u90fd\u4f1a\u8fd4\u56detrue\n\t\t\t *\/\n\t\t\t\/\/console.log(dog instanceof Object);\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<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 * \u521b\u5efa\u4e00\u4e2aPerson\u6784\u9020\u51fd\u6570\n\t\t\t * \t- \u5728Person\u6784\u9020\u51fd\u6570\u4e2d\uff0c\u4e3a\u6bcf\u4e00\u4e2a\u5bf9\u8c61\u90fd\u6dfb\u52a0\u4e86\u4e00\u4e2asayName\u65b9\u6cd5\uff0c\n\t\t\t * \t\t\u76ee\u524d\u6211\u4eec\u7684\u65b9\u6cd5\u662f\u5728\u6784\u9020\u51fd\u6570\u5185\u90e8\u521b\u5efa\u7684\uff0c\n\t\t\t * \t\t\t\u4e5f\u5c31\u662f\u6784\u9020\u51fd\u6570\u6bcf\u6267\u884c\u4e00\u6b21\u5c31\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684sayName\u65b9\u6cd5\n\t\t\t * \t\t\u4e5f\u662f\u6240\u6709\u5b9e\u4f8b\u7684sayName\u90fd\u662f\u552f\u4e00\u7684\u3002\n\t\t\t * \t\t\u8fd9\u6837\u5c31\u5bfc\u81f4\u4e86\u6784\u9020\u51fd\u6570\u6267\u884c\u4e00\u6b21\u5c31\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u65b9\u6cd5\uff0c\n\t\t\t * \t\t\t\u6267\u884c10000\u6b21\u5c31\u4f1a\u521b\u5efa10000\u4e2a\u65b0\u7684\u65b9\u6cd5\uff0c\u800c10000\u4e2a\u65b9\u6cd5\u90fd\u662f\u4e00\u6478\u4e00\u6837\u7684\n\t\t\t * \t\t\t\u8fd9\u662f\u5b8c\u5168\u6ca1\u6709\u5fc5\u8981\uff0c\u5b8c\u5168\u53ef\u4ee5\u4f7f\u6240\u6709\u7684\u5bf9\u8c61\u5171\u4eab\u540c\u4e00\u4e2a\u65b9\u6cd5\n\t\t\t *\/\n\t\t\tfunction Person(name , age , gender){\n\t\t\t\tthis.name = name;\n\t\t\t\tthis.age = age;\n\t\t\t\tthis.gender = gender;\n\t\t\t\t\/\/\u5411\u5bf9\u8c61\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b9\u6cd5\n\t\t\t\t\/\/this.sayName = fun;\n\t\t\t}\n\t\t\t\n\t\t\t\/\/\u5c06sayName\u65b9\u6cd5\u5728\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\u5b9a\u4e49\n\t\t\t\/*\n\t\t\t * \u5c06\u51fd\u6570\u5b9a\u4e49\u5728\u5168\u5c40\u4f5c\u7528\u57df\uff0c\u6c61\u67d3\u4e86\u5168\u5c40\u4f5c\u7528\u57df\u7684\u547d\u540d\u7a7a\u95f4\n\t\t\t * \t\u800c\u4e14\u5b9a\u4e49\u5728\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\u4e5f\u5f88\u4e0d\u5b89\u5168\n\t\t\t *\/\n\t\t\t\/*function fun(){\n\t\t\t\talert(\"Hello\u5927\u5bb6\u597d\uff0c\u6211\u662f:\"+this.name);\n\t\t\t};*\/\n\t\t\t\/\/\u5411\u539f\u578b\u4e2d\u6dfb\u52a0sayName\u65b9\u6cd5\n\t\t\tPerson.prototype.sayName = function(){\n\t\t\t\talert(\"Hello\u5927\u5bb6\u597d\uff0c\u6211\u662f:\"+this.name);\n\t\t\t};\n\t\t\t\n\t\t\t\/\/\u521b\u5efa\u4e00\u4e2aPerson\u7684\u5b9e\u4f8b\n\t\t\tvar per = new Person(\"\u5b59\u609f\u7a7a\",18,\"\u7537\");\n\t\t\tvar per2 = new Person(\"\u732a\u516b\u6212\",28,\"\u7537\");\n\t\t\tper.sayName();\n\t\t\tper2.sayName();\n\t\t\t\n\t\t\t\/\/console.log(per.sayName == per2.sayName);\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<p>&nbsp;<\/p>\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\/322"}],"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=322"}],"version-history":[{"count":0,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/322\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/media?parent=322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/categories?post=322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/tags?post=322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}