{"id":170,"date":"2026-01-20T09:14:03","date_gmt":"2026-01-20T01:14:03","guid":{"rendered":"https:\/\/mitongxue.cn\/?p=170"},"modified":"2026-06-04T09:19:40","modified_gmt":"2026-06-04T01:19:40","slug":"js%e5%8e%9f%e5%9e%8b%e9%93%be","status":"publish","type":"post","link":"https:\/\/mitongxue.cn\/index.php\/2026\/01\/20\/js%e5%8e%9f%e5%9e%8b%e9%93%be\/","title":{"rendered":"JS\u539f\u578b\u94fe"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u751f\u4ea7\u5bf9\u8c61\u7684\u65b9\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u540c\u7684\u8bed\u8a00\uff0c<strong>\u751f\u4ea7\u5bf9\u8c61\u7684\u65b9\u5f0f<\/strong>\u5176\u5b9e\u5e76\u4e0d\u76f8\u540c\uff0c\u6574\u4f53\u6765\u8bb2\uff0c<strong>\u53ef\u4ee5\u5206\u4e3a\u4e24\u5927\u7c7b<\/strong>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u57fa\u4e8e<strong>\u7c7b<\/strong>\u751f\u4ea7\u5bf9\u8c61<\/li>\n\n\n\n<li>\u57fa\u4e8e<strong>\u539f\u578b<\/strong>\u751f\u4ea7\u5bf9\u8c61<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u57fa\u4e8e\u7c7b\u751f\u4ea7\u5bf9\u8c61<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u751f\u4ea7\u5bf9\u8c61\u7684\u65b9\u5f0f\u53ef\u80fd\u662f\u6700\u5e38\u89c1\u7684\u65b9\u5f0f\uff0c\u5f88\u591a\u8bed\u8a00\u4e2d<strong>\u8981\u751f\u4ea7\u4e00\u4e2a\u5bf9\u8c61\uff0c\u90fd\u9700\u8981\u5148\u4e66\u5199\u4e00\u4e2a\u7c7b\uff0c\u7136\u540e\u901a\u8fc7\u7c7b\u6765\u5b9e\u4f8b\u5316\u5bf9\u8c61<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Person {\n\n  private String name;\n  private int age;\n\n  public Person(String name, int age) {\n    this.name = name;\n    this.age = age;\n  }\n\n  public void sayHello() {\n    System.out.println(\"\u6211\u7684\u540d\u5b57\u662f\" + name + \"\uff0c\u6211\u4eca\u5e74\" + age + \"\u5c81\");\n  }\n\n  public static void main(String&#91;] args) {\n    Person p = new Person(\"\u5f20\u4e09\", 18);\n    p.sayHello();\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Person:\n  def __init__(self, name, age):\n      self.name = name\n      self.age = age\n\n  def say_hello(self):\n      print(f\"\u6211\u7684\u540d\u5b57\u662f{self.name}\uff0c\u6211\u4eca\u5e74{self.age}\u5c81\")\n\np = Person(\"\u5f20\u4e09\", 18)\np.say_hello()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">PHP<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Person {\n  private $name;\n  private $age;\n\n  public function __construct($name, $age) {\n      $this->name = $name;\n      $this->age = $age;\n  }\n\n  public function sayHello() {\n      echo \"\u6211\u7684\u540d\u5b57\u662f\" . $this->name . \"\uff0c\u6211\u4eca\u5e74\" . $this->age . \"\u5c81\\n\";\n  }\n}\n\n$p = new Person(\"\u5f20\u4e09\", 18);\n$p->sayHello();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u770b\u5230\uff0c\u5f88\u591a\u4e3b\u6d41\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u90fd\u662f\u901a\u8fc7\u5b9e\u4f8b\u5316\u7c7b\u7684\u65b9\u5f0f\u6765\u4ea7\u751f\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\uff0c\u8fd9\u5e76\u975e\u552f\u4e00\u7684\u65b9\u5f0f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u57fa\u4e8e\u539f\u578b\u751f\u4ea7\u5bf9\u8c61<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd8\u6709\u4e00\u79cd\u65b9\u5f0f\uff0c\u5219\u662f\u57fa\u4e8e\u539f\u578b\u6765\u751f\u4ea7\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u65b9\u5f0f\u7684\u6838\u5fc3\u601d\u60f3\u5c31\u662f\uff1a<strong>\u5148\u6709\u4e00\u4e2a\u5bf9\u8c61 A\uff0c\u7136\u540e\u4f60\u8981\u751f\u4ea7\u4e00\u4e2a\u65b0\u7684\u5bf9\u8c61 B\uff0c\u5c31\u5148\u514b\u9686\u4e00\u4efd\u5bf9\u8c61 A \u4ece\u800c\u5f97\u5230\u65b0\u5bf9\u8c61 B\uff0c\u65b0\u7684\u5bf9\u8c61 B \u53ef\u4ee5\u6dfb\u52a0\u65b0\u7684\u5c5e\u6027\u6216\u8005\u65b9\u6cd5\uff0c\u5bf9\u4e8e\u5bf9\u8c61 B \u800c\u8a00\uff0c\u5bf9\u8c61 A \u5c31\u662f\u81ea\u5df1\u7684\u539f\u578b\u5bf9\u8c61<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u91c7\u7528\u8fd9\u79cd\u751f\u4ea7\u5bf9\u8c61\u65b9\u5f0f\u7684\u8bed\u8a00\uff0c\u867d\u7136\u4e0d\u50cf\u4e0a\u9762\u6240\u7f57\u5217\u7684\u90a3\u4e9b\u8bed\u8a00\u90a3\u4e48\u4e3b\u6d41\uff0c\u4f46\u662f\u4e5f\u786e\u786e\u5b9e\u5b9e\u5b58\u5728\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Self<\/strong> &#8211; Self\u8bed\u8a00\u5f7b\u5e95\u91c7\u7528\u539f\u578b\u6a21\u5f0f\uff0c\u6ca1\u6709\u7c7b\u7684\u6982\u5ff5\uff0c\u5bf9\u8c61\u76f4\u63a5\u4ece\u5176\u4ed6\u5bf9\u8c61\u514b\u9686\u5e76\u53ef\u80fd\u4fee\u6539\u3002<\/li>\n\n\n\n<li><strong>Lua<\/strong> &#8211; \u867d\u7136Lua\u4e2d\u6709\u6a21\u5757\u548c\u5305\u7684\u6982\u5ff5\uff0c\u4f46\u5176\u8868\uff08table\uff09\u7ed3\u6784\u53ef\u4ee5\u7528\u6765\u5b9e\u73b0\u539f\u578b\u5f0f\u7ee7\u627f\u3002<\/li>\n\n\n\n<li><strong>Io<\/strong> &#8211; Io\u662f\u4e00\u4e2a\u7eaf\u539f\u578b\u8bed\u8a00\uff0c\u6240\u6709\u5bf9\u8c61\u90fd\u6765\u81ea\u4e8e\u514b\u9686\u5176\u4ed6\u5bf9\u8c61\u3002<\/li>\n\n\n\n<li><strong>Proto<\/strong> &#8211; \u4e00\u4e2a\u8f83\u5c11\u77e5\u7684\u8bed\u8a00\uff0c\u4e13\u95e8\u8bbe\u8ba1\u4e3a\u539f\u578b\u7ee7\u627f\u8bed\u8a00\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">3. JS \u751f\u4ea7\u5bf9\u8c61<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e03\u5170\u767b\u30fb\u827e\u5947\u5728\u8bbe\u8ba1\u8fd9\u95e8\u8bed\u8a00\u65f6\uff0c<strong>\u9009\u62e9\u4e86\u539f\u578b\u7684\u65b9\u5f0f\u6765\u751f\u4ea7\u5bf9\u8c61<\/strong>\uff0c\u4ed6\u7ed9\u51fa\u7684\u7406\u7531\u6709\u4e24\u4e2a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4ed6\u81ea\u5df1\u672c\u8eab\u662f\u4e00\u4e2a Lisp \u7a0b\u5e8f\u5458\uff0c\u4e3b\u8981\u65b9\u5411\u548c\u5174\u8da3\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0c\u56e0\u6b64\u5728\u7f16\u7a0b\u8303\u5f0f\u4e0a\u66f4\u559c\u6b22\u5c5e\u4e8e\u58f0\u660e\u5f0f\u7f16\u7a0b\u7684\u51fd\u6570\u5f0f\u7f16\u7a0b\u3002<\/li>\n\n\n\n<li>JS \u8bbe\u8ba1\u7684\u521d\u8877\uff0c\u5b9a\u4f4d\u662f\u4e00\u95e8\u9762\u5411\u975e\u4e13\u4e1a\u7684\u5f00\u53d1\u4eba\u5458\uff08\u4f8b\u5982\u7f51\u9875\u8bbe\u8ba1\u8005\uff09\u7684\u8bed\u8a00\u3002\u7531\u4e8e\u5927\u90e8\u5206\u7f51\u9875\u8bbe\u8ba1\u8005\u90fd\u6ca1\u6709\u4efb\u4f55\u7684\u7f16\u7a0b\u80cc\u666f\uff0c\u56e0\u6b64\u8fd9\u95e8\u8bed\u8a00\u5e94\u8be5\u5c3d\u53ef\u80fd\u7684\u7b80\u5355\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 JS \u4e2d\uff0c\u4f60\u53ef\u4ee5\u5f88\u8f7b\u677e\u7684\u67e5\u770b\u4e00\u4e2a\u5bf9\u8c61\u7684\u539f\u578b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const obj = {};\nconsole.log(obj.__proto__);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u4e00\u4e2a\u7ed3\u8bba\uff1a<strong>\u5728 JS \u4e2d\uff0c\u65e0\u8bba\u4f60\u8fd9\u4e2a\u5bf9\u8c61\u662f\u5982\u4f55\u4e66\u5199\u7684\uff0c\u8be5\u5bf9\u8c61\u90fd\u6709\u81ea\u5df1\u7684\u539f\u578b\u5bf9\u8c61<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 ES5 \u4e2d\u63d0\u4f9b\u4e86\u4e00\u4e2a Object.create \u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u5c31\u53ef\u4ee5\u6307\u5b9a\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const person = {\n  arm: 2,\n  legs: 2,\n  walk() {\n    console.log(\"walking\");\n  },\n};\n\nconst john = Object.create(person, {\n  name: {\n    value: \"John\",\n    enumerable: true,\n  },\n  age: {\n    value: 18,\n    enumerable: true,\n  },\n});\nconsole.log(john.__proto__ === person); \/\/ true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e03\u5170\u767b\u30fb\u827e\u5947\u6700\u521d\u5728\u8bbe\u8ba1\u8fd9\u95e8\u8bed\u8a00\u65f6\u7684\u6784\u60f3\u662f\u5f88\u7f8e\u597d\u7684\uff0c\u4f46\u662f\u73b0\u5b9e\u662f\u5f88\u6b8b\u9177\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u65f6\u7684\u5927\u73af\u5883\u4e0b\uff0c\u6d41\u884c\u7684\u662f\u201c\u57fa\u4e8e\u7c7b\u751f\u4ea7\u5bf9\u8c61\u201d\u7684\u65b9\u5f0f\uff0c\u5176\u4e2d\u53c8\u4ee5 Java\u3001C++ \u8fd9\u6837\u7684\u8bed\u8a00\u6700\u4e3a\u4ee3\u8868\u3002\u53e6\u5916\uff0c\u5f53\u65f6\u7f51\u666f\u516c\u53f8\u7684\u6574\u4e2a\u7ba1\u7406\u5c42\uff0c\u90fd\u662f Java \u8bed\u8a00\u7684\u4fe1\u5f92\uff0c\u56e0\u6b64\u5728 1995 \u5e74 5 \u6708\uff0c\u7f51\u666f\u516c\u53f8\u505a\u51fa\u51b3\u7b56\uff0c\u672a\u6765\u7684\u7f51\u9875\u811a\u672c\u8bed\u8a00\u5fc5\u987b\u201c\u770b\u4e0a\u53bb\u4e0e Java \u8db3\u591f\u76f8\u4f3c\u201d\uff0c\u4f46\u662f\u9700\u8981\u6bd4 Java \u7b80\u5355\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ca1\u529e\u6cd5\uff0c\u53d7\u5230\u4e86\u516c\u53f8\u9ad8\u5c42\u7684\u547d\u4ee4\uff0c\u5e03\u5170\u767b\u30fb\u827e\u5947\u6e38\u4e0d\u5f97\u4e0d\u5bf9 JS \u8fdb\u884c\u6539\u9020\uff0c\u6dfb\u52a0\u4e86 this\u3001new \u8fd9\u4e9b\u5173\u952e\u5b57\uff0c\u4f7f\u5176<strong>\u770b\u4e0a\u53bb\u50cf\u662f\u57fa\u4e8e\u7c7b\u751f\u4ea7\u7684\u5bf9\u8c61<\/strong>\u3002\u4e0d\u8fc7\u65e9\u671f\u6ca1\u6709 class \u5173\u952e\u5b57\uff0c\u600e\u4e48\u529e\u5462\uff1f\u6ca1\u9519\uff0c\u5c31\u662f<strong>\u4f7f\u7528 function \u6765\u6a21\u62df\u7c7b\uff0c\u4e3a\u4e86\u533a\u5206\u666e\u901a\u51fd\u6570\uff0c\u4e00\u4e2a\u4e0d\u6210\u6587\u7684\u89c4\u5b9a\u5c31\u662f\u6784\u9020\u51fd\u6570\u540d\u79f0\u9996\u5b57\u6bcd\u5927\u5199\u3002<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function Computer(name, price){\n  this.name = name;\n  this.price = price;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u7684\u6784\u9020\u51fd\u6570\u672c\u8eab\u662f\u666e\u901a\u7684\u51fd\u6570\uff0c\u4f46\u5982\u679c\u4f60\u4f7f\u7528 new \u7684\u65b9\u5f0f\u6765\u8c03\u7528\uff0c\u6267\u884c\u673a\u5236\u5219\u548c\u666e\u901a\u7684\u51fd\u6570\u8c03\u7528\u4e0d\u4e00\u6837\uff0c\u4f1a\u7ecf\u5386\u5982\u4e0b\u7684\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684\u7b80\u5355 JS \u5bf9\u8c61\uff08\u5373 { } \uff09<\/li>\n\n\n\n<li>\u4e3a\u6b65\u9aa4 1 \u65b0\u521b\u5efa\u7684\u5bf9\u8c61\u6dfb\u52a0\u5c5e\u6027 __proto__\uff0c\u5c06\u8be5\u5c5e\u6027\u94fe\u63a5\u81f3\u6784\u9020\u51fd\u6570\u7684\u539f\u578b\u5bf9\u8c61<\/li>\n\n\n\n<li>\u5c06\u6b65\u9aa4 1 \u65b0\u521b\u5efa\u7684\u5bf9\u8c61\u4f5c\u4e3a this \u7684\u4e0a\u4e0b\u6587<\/li>\n\n\n\n<li>\u5982\u679c\u8be5\u51fd\u6570\u6ca1\u6709\u8fd4\u56de\u5bf9\u8c61\uff0c\u5219\u8fd4\u56de this<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>function Computer(name, price) {\n  \/\/ 1. \u521b\u5efa\u4e00\u4e2a\u666e\u901a\u7684\u5bf9\u8c61\n  \/\/ const obj = {};\n\n  \/\/ 2. \u8bbe\u7f6e\u8be5\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\n  \/\/ obj.__proto__ = Computer.prototype;\n\n  \/\/ 3. \u8bbe\u7f6e this \u7684\u6307\u5411\uff0c\u6307\u5411\u8be5 obj\n  \/\/ this ---> obj\n  this.name = name; \/\/ {name: \"\u534e\u4e3a\"}\n  this.price = price; \/\/ {name: \"\u534e\u4e3a\", price: 5000}\n\n  \/\/ 4. \u5982\u679c\u4ee3\u7801\u91cc\u9762\u6ca1\u6709\u8fd4\u56de\u5bf9\u8c61\uff0c\u90a3\u4e48\u8fd4\u56de\u8be5 this\n  \/\/ return this;\n}\nconst huawei = new Computer(\"\u534e\u4e3a\", 5000);\nconsole.log(huawei);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8fd9\u5176\u5b9e\u5c31\u662f JS \u4e2d\u51fd\u6570\u4e8c\u4e49\u6027\u7684\u7531\u6765<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\uff0c\u4e0d\u7ba1 JS \u5982\u4f55\u6a21\u62df\u9762\u5411\u5bf9\u8c61\u7684\u7279\u6027\uff0c\u54ea\u6015 ES6 \u751a\u81f3\u65b0\u589e\u4e86 class \u5173\u952e\u5b57\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Computer {\n  constructor(name, price) {\n    this.name = name;\n    this.price = price;\n  }\n}\nconst huawei = new Computer(\"\u534e\u4e3a\", 5000);\nconsole.log(huawei);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">JS \u5e95\u5c42\u4ecd\u7136\u662f\u4e00\u95e8\u57fa\u4e8e\u539f\u578b\u7684\u8bed\u8a00\uff0c\u8fd9\u4e00\u70b9\u662f\u4e0d\u4f1a\u6539\u53d8\u7684\u3002\u73b0\u5728\u4e0d\u4f1a\u53d8\uff0c\u672a\u6765\uff0c\u4e5f\u4e0d\u4f1a\u53d8\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u539f\u578b\u5bf9\u8c61\u4e0e\u539f\u578b\u94fe<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u4e09\u89d2\u5173\u7cfb<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u5bf9\u8c61\u662f\u7531\u6784\u9020\u51fd\u6570\u751f\u4ea7\u7684\uff0c\u524d\u9762\u6211\u4eec\u8bf4\u8fc7\uff0c\u90a3\u53ea\u662f\u8868\u8c61\uff0c\u53ea\u662f\u6a21\u62df\uff0c\u6700\u7ec8\u5e95\u5c42\u4ecd\u7136\u91c7\u7528\u7684\u662f\u539f\u578b\u7684\u65b9\u5f0f\u3002\u5e76\u4e14\u6784\u9020\u51fd\u6570\u3001\u5b9e\u4f8b\u5bf9\u8c61\u4ee5\u53ca\u539f\u578b\u5bf9\u8c61\u8fd9\u4e09\u8005\u4e4b\u95f4\uff0c\u8fd8\u5b58\u5728\u4e00\u4e2a\u8457\u540d\u7684\u4e09\u89d2\u5173\u7cfb\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"560\" height=\"353\" src=\"https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/06\/image-25.png\" alt=\"\" class=\"wp-image-171\" srcset=\"https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/06\/image-25.png 560w, https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/06\/image-25-300x189.png 300w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91cc\u7684\u4e09\u89d2\u5173\u7cfb\u6307\u7684\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6784\u9020\u51fd\u6570<\/li>\n\n\n\n<li>\u5b9e\u4f8b\u5bf9\u8c61<\/li>\n\n\n\n<li>\u539f\u578b\u5bf9\u8c61<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e09\u8005\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<strong>\u5728 JS \u4e2d\uff0c\u53ea\u8981\u662f\u7531\u6784\u9020\u51fd\u6570 new \u51fa\u6765\u7684\u5bf9\u8c61\uff0c\u90fd\u6ee1\u8db3\u8fd9\u6837\u7684\u5173\u7cfb\uff0c\u4e0d\u7ba1\u4f60\u662f\u81ea\u5b9a\u4e49\u6784\u9020\u51fd\u6570\u8fd8\u662f\u5185\u7f6e\u7684\u6784\u9020\u51fd\u6570<\/strong>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function Computer(){}\nconst c = new Computer();\nconsole.log(c.__proto__ === Computer.prototype);\nconsole.log(c.constructor === Computer);\nconsole.log(c.constructor === Computer.prototype.constructor);\nconsole.log(\"-------\");\nconsole.log(&#91;].__proto__ === Array.prototype);\nconsole.log(&#91;].constructor === Array);\nconsole.log(\"-------\");\nconsole.log(1..__proto__ === Number.prototype);\nconsole.log(1..constructor === Number);\nconsole.log(\"-------\");\nconsole.log(true.__proto__ === Boolean.prototype);\nconsole.log(true.constructor === Boolean);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u539f\u578b\u94fe\u5168\u8c8c\u56fe<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6574\u4e2a\u539f\u578b\u94fe\u7684\u5168\u8c8c\u56fe\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"860\" height=\"518\" src=\"https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/06\/image-26.png\" alt=\"\" class=\"wp-image-172\" srcset=\"https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/06\/image-26.png 860w, https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/06\/image-26-300x181.png 300w, https:\/\/mitongxue.cn\/wp-content\/uploads\/2026\/06\/image-26-768x463.png 768w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JS \u4e2d\u7684\u5bf9\u8c61\u5927\u4f53\u4e0a\u5206\u4e3a\u4e24\u5927\u7c7b\uff1a<strong>\u666e\u901a\u5bf9\u8c61<\/strong> \u548c <strong>\u6784\u9020\u5668\u5bf9\u8c61<\/strong><\/li>\n\n\n\n<li>\u65e0\u8bba\u662f <strong>\u666e\u901a\u5bf9\u8c61<\/strong> \u8fd8\u662f <strong>\u6784\u9020\u5668\u5bf9\u8c61<\/strong>\uff0c\u90fd\u4f1a\u6709\u81ea\u5df1\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u901a\u8fc7 __proto__ \u8fd9\u4e2a\u9690\u5f0f\u5c5e\u6027\uff0c\u5c31\u80fd\u627e\u5230\u81ea\u5df1\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u5e76\u4e14<strong>\u4e00\u76f4\u5411\u4e0a\u627e\uff0c\u6700\u7ec8\u4f1a\u5230\u8fbe null.<\/strong><\/li>\n\n\n\n<li><strong>\u666e\u901a\u5bf9\u8c61<\/strong> \u548c <strong>\u6784\u9020\u5668\u5bf9\u8c61<\/strong> \u7684\u533a\u522b\u5728\u4e8e\u662f\u5426\u80fd\u591f\u5b9e\u4f8b\u5316\uff0c<strong>\u6784\u9020\u5668\u5bf9\u8c61<\/strong>\u53ef\u4ee5\u901a\u8fc7 new \u7684\u5f62\u5f0f\u521b\u5efa\u65b0\u7684\u5b9e\u4f8b\u5bf9\u8c61\uff0c\u8fd9\u4e9b\u5b9e\u4f8b\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\u4e00\u76f4\u5f80\u4e0a\u627e\u6700\u7ec8\u4ecd\u7136\u662f\u5230\u8fbe null.<\/li>\n\n\n\n<li>\u53ea\u6709 <strong>\u6784\u9020\u5668\u5bf9\u8c61<\/strong> \u624d\u6709 prototype \u5c5e\u6027\uff0c\u5176 prototype \u5c5e\u6027\u6307\u5411\u5b9e\u4f8b\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61<\/li>\n\n\n\n<li>\u6240\u6709 <strong>\u6784\u9020\u5668\u5bf9\u8c61<\/strong> \u7684\u539f\u578b\u5bf9\u8c61\u5747\u4e3a Function.prototype<\/li>\n\n\n\n<li>\u65e0\u8bba\u662f <strong>\u666e\u901a\u5bf9\u8c61<\/strong> \u8fd8\u662f <strong>\u6784\u9020\u5668\u5bf9\u8c61<\/strong>\uff0c\u6700\u7ec8\u7684 constructor \u6307\u5411 Function\uff0c\u800c Function \u7684 constructor \u6307\u5411\u81ea\u5df1\u672c\u8eab\u3002<\/li>\n\n\n\n<li>Object \u8fd9\u4e2a <strong>\u6784\u9020\u5668\u5bf9\u8c61<\/strong> \u6bd4\u8f83\u7279\u6b8a\uff0c\u5b9e\u4f8b\u5316\u51fa\u6765\u7684\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\u76f4\u63a5\u5c31\u662f Object.prototype\uff0c\u800c\u5176\u4ed6\u7684\u6784\u9020\u5668\u5bf9\u8c61\uff0c\u5176\u5b9e\u4f8b\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\u4e3a\u5bf9\u5e94\u7684 xxx.prototype\uff0c\u518d\u5f80\u4e00\u5c42\u624d\u662f Object.prototype.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u539f\u578b\u94fe\u5b9e\u9645\u5e94\u7528<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b66\u4e60\u539f\u578b\u76f8\u5173\u7684\u77e5\u8bc6\u6709\u4ec0\u4e48\u7528\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u5b9e\u4f60\u53ea\u6709\u4e86\u89e3\u4e86\u539f\u578b\uff0c\u4f60\u624d\u80fd\u6df1\u523b\u7684\u7406\u89e3\u4e3a\u4ec0\u4e48\u65b9\u6cd5\u8981\u6302\u5728\u539f\u578b\u5bf9\u8c61\u4e0a\u9762\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function Computer(name, price) {\n  this.name = name;\n  this.price = price;\n}\nComputer.prototype.showPrice = function () {\n  console.log(`${this.name}\u7684\u7535\u8111\u4ef7\u683c\u4e3a${this.price}`);\n};\n\nconst huawei = new Computer(\"\u534e\u4e3a\", 5000);\nconst apple = new Computer(\"\u82f9\u679c\", 8000);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e4b\u6240\u4ee5\u8981\u6302\u5728\u539f\u578b\u5bf9\u8c61\u4e0a\u9762\uff0c\u662f\u56e0\u4e3a\u7531<strong>\u6784\u9020\u51fd\u6570\u5b9e\u4f8b\u5316\u51fa\u6765\u7684\u6bcf\u4e00\u4e2a\u5b9e\u4f8b\u5bf9\u8c61\uff0c\u5c5e\u6027\u503c\u662f\u4e0d\u76f8\u540c\u7684\uff0c\u6240\u4ee5\u9700\u8981\u6bcf\u4e2a\u5bf9\u8c61\u72ec\u7acb\u6709\u4e00\u4efd<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f<strong>\u5bf9\u4e8e\u65b9\u6cd5\u800c\u8a00\uff0c\u6240\u6709\u5bf9\u8c61\u90fd\u662f\u76f8\u540c\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u4e0d\u9700\u8981\u6bcf\u4e2a\u5bf9\u8c61\u62e5\u6709\u4e00\u4efd\uff0c\u76f4\u63a5\u6302\u5728\u539f\u578b\u5bf9\u8c61\u4e0a\u9762\u5171\u7528\u4e00\u4efd\u5373\u53ef<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u73b0\u5728\u4e5f\u5c31\u80fd\u591f\u7406\u89e3\uff0c\u4e3a\u4ec0\u4e48\u6240\u6709\u7684\u6784\u9020\u51fd\u6570\u5185\u7f6e\u65b9\u6cd5\u90fd\u662f\u6302\u5728\u539f\u578b\u5bf9\u8c61\u4e0a\u9762\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a<a href=\"https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\">https:\/\/developer.mozilla.org\/zh-CN\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53e6\u5916\uff0c\u867d\u7136\u6211\u4eec\u80fd\u591f\u8f7b\u677e\u7684\u7ed9\u5185\u7f6e\u7684\u6784\u9020\u5668\u51fd\u6570\u6dfb\u52a0\u5c5e\u6027\u548c\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Number.prototype.isEven = function () {\n    return this % 2 === 0;\n}\nNumber.prototype.isOdd = function () {\n    return this % 2 === 1;\n}\nconst i = 42;\nconsole.log(i.isEven()); \/\/ true\nconst j = 13;\nconsole.log(j.isOdd()); \/\/ true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f<strong>\u76ee\u524d JS \u793e\u533a\u7684\u5927\u90e8\u5206\u4eba\u90fd\u4e0d\u63a8\u8350\u8fd9\u4e48\u505a\uff0c\u8fd9\u6837\u7684\u505a\u6cd5\u5f80\u5f80\u88ab\u79f0\u4e4b\u7334\u5b50\u8865\u4e01\uff08monkey-patching\uff09<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5927\u90e8\u5206\u4eba\u7684\u89c2\u70b9\u662f\u201c\u522b\u800d\u6d41\u6c13\uff0c\u4e0d\u662f\u4f60\u7684\u5bf9\u8c61\u522b\u52a8\u624b\u52a8\u811a\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u79cd\u66f4\u597d\u7684\u6700\u4f73\u5b9e\u8df5\u662f\u7ee7\u627f\u60f3\u8981\u4fee\u6539\u7684\u6784\u9020\u51fd\u6570\uff0c\u5728\u5b50\u7c7b\u4e0a\u9762\u6dfb\u52a0\u65b0\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class myNum extends Number{\n    constructor(...args){\n        super(...args);\n    }\n    zhangsan(){}\n}\nconst i = new myNum(1);\ni.zhangsan();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u539f\u578b\u94fe\u76f8\u5173\u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Object.getPrototypeOf( )<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u65b9\u6cd5\u7528\u4e8e\u67e5\u627e\u4e00\u4e2a\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function Computer(){}\nconst c = new Computer();\nconsole.log(Object.getPrototypeOf(c) === c.__proto__);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. instanceof \u64cd\u4f5c\u7b26<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5224\u65ad\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u662f\u4e00\u4e2a\u6784\u9020\u51fd\u6570\u7684\u5b9e\u4f8b\u3002\u5982\u679c\u662f\u8fd4\u56de <em>true<\/em>\uff0c\u5426\u5219\u5c31\u8fd4\u56de <em>false<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function Computer(){}\nconst c = new Computer();\nconsole.log(c instanceof Computer); \/\/ true\nconsole.log(c instanceof Array); \/\/ false\nconsole.log(&#91;] instanceof Array); \/\/ true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. isPrototypeOf( )<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3b\u8981\u7528\u4e8e\u68c0\u6d4b\u4e00\u4e2a\u5bf9\u8c61\u662f\u5426\u662f\u4e00\u4e2a\u53e6\u4e00\u4e2a\u5bf9\u8c61\u7684\u539f\u578b\u5bf9\u8c61\uff0c\u5982\u679c\u662f\u8fd4\u56de true\uff0c\u5426\u5219\u5c31\u8fd4\u56de false<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function Computer(){}\nconst c = new Computer();\nconsole.log(Computer.prototype.isPrototypeOf(c)); \/\/ true\nconsole.log(Computer.prototype.isPrototypeOf(&#91;])); \/\/ false\nconsole.log(Array.prototype.isPrototypeOf(&#91;])); \/\/ true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. hasOwnProperty( )<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5224\u65ad\u4e00\u4e2a\u5c5e\u6027\u662f\u5b9a\u4e49\u5728\u5bf9\u8c61\u672c\u8eab\u4e0a\u9762\u8fd8\u662f\u4ece\u539f\u578b\u5bf9\u8c61\u4e0a\u9762\u7ee7\u627f\u800c\u6765\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u662f\u672c\u8eab\u7684\uff0c\u5219\u8fd4\u56de true\uff0c\u5982\u679c\u662f\u7ee7\u627f\u800c\u6765\u7684\uff0c\u5219\u8fd4\u56de false<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const person = {\n  arm: 2,\n  legs: 2,\n  walk() {\n    console.log(\"walking\");\n  },\n};\n\nconst john = Object.create(person, {\n  name: {\n    value: \"John\",\n    enumerable: true,\n  },\n  age: {\n    value: 18,\n    enumerable: true,\n  },\n});\nconsole.log(john.hasOwnProperty(\"name\")); \/\/ true\nconsole.log(john.hasOwnProperty(\"arms\")); \/\/ false<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u751f\u4ea7\u5bf9\u8c61\u7684\u65b9\u5f0f \u4e0d\u540c\u7684\u8bed\u8a00\uff0c\u751f\u4ea7\u5bf9\u8c61\u7684\u65b9\u5f0f\u5176\u5b9e\u5e76\u4e0d..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,11],"tags":[],"class_list":["post-170","post","type-post","status-publish","format-standard","hentry","category-js","category-front"],"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":""},"author_info":{"info":["\u9648 \u67d0\u4eba"]},"category_info":"<a href=\"https:\/\/mitongxue.cn\/index.php\/category\/front\/js\/\" rel=\"category tag\">JS<\/a> <a href=\"https:\/\/mitongxue.cn\/index.php\/category\/front\/\" rel=\"category tag\">\u524d\u7aef<\/a>","tag_info":"\u524d\u7aef","comment_count":"0","_links":{"self":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":1,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/170\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}