{"id":1004,"date":"2022-04-12T14:46:37","date_gmt":"2022-04-12T06:46:37","guid":{"rendered":"http:\/\/zhuxinyong.com\/?p=1004"},"modified":"2023-02-16T14:39:41","modified_gmt":"2023-02-16T06:39:41","slug":"4-javascript-zhong-de-dui-xiang-shi-shen-me","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1004","title":{"rendered":"4 &#8211; JavaScript \u4e2d\u7684\u5bf9\u8c61\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/04\/16497710545107.jpg\" alt=\"\" \/><\/p>\n<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"https:\/\/dev.to\/bhagatparwinder\/what-are-objects-in-javascript-19oi\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.to\/bhagatparwinder\/what-are-objects-in-javascript-19oi<\/a><\/p>\n<h3><a id=\"%E4%BB%80%E4%B9%88%E6%98%AF%E5%AF%B9%E8%B1%A1%EF%BC%9F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4ec0\u4e48\u662f\u5bf9\u8c61\uff1f<\/h3>\n<p>\u5bf9\u8c61\u662f JavaScript \u4e2d\u57fa\u7840\u7684\u6784\u6210\u6a21\u5757\uff0cJavaScript \u4e2d\u4e00\u5207\u7686\u53ef\u8868\u793a\u4e3a\u5bf9\u8c61\u3002<\/p>\n<p>\u5bf9\u8c61\u662f\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\uff0ckey \u662f\u5bf9 value \u7684\u5f15\u7528\u3002\u4e0b\u9762\u770b\u4e00\u4e0b\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-plain_text\">const person = {\n    firstName: &quot;Parwinder&quot;,\n    lastName: &quot;Bhagat&quot;,\n    'my name':'Parwinder Bhagat',\n    age: 33,\n    nicknames: [&quot;Ricky&quot;, &quot;P&quot;],\n    vehicles: {\n        car: &quot;BMW X5&quot;,\n        motorcycle: &quot;Honda Rebel 500&quot;\n    }\n}\n<\/code><\/pre>\n<p>\u4e0a\u9762\u6211\u58f0\u660e\u4e86\u4e00\u4e2a <strong>person<\/strong> \u7684\u5bf9\u8c61\uff0c\u5b83\u662f\u72ec\u7acb\u6570\u636e\u7684\u96c6\u5408\u3002\u5bf9\u8c61\u662f\u7528\u4e00\u4e2a **{}**\u8868\u793a\u7684\u3002\u5728\u4e2d\u62ec\u53f7\u5185\uff0c\u5de6\u8fb9\u662f key \uff08\u4e0d\u9700\u8981\u4f7f\u7528\u5f15\u53f7\uff09\u5192\u53f7\u53f3\u8fb9\u662f value \u3002<\/p>\n<blockquote>\n<p>\u6ce8\u610f\uff1a\u65f6\u523b\u8bb0\u4f4f\u5bf9\u8c61\u4e2d key \u7684\u987a\u5e8f\u6ca1\u5173\u7cfb\uff0c\u65e0\u6cd5\u4fdd\u8bc1\u5bf9\u8c61\u4e2d\u7684 key \u987a\u5e8f\u3002<\/p>\n<\/blockquote>\n<h3><a id=\"%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E5%AF%B9%E8%B1%A1%E4%B8%AD%E7%9A%84%E5%80%BC%EF%BC%9F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5982\u4f55\u83b7\u53d6\u5bf9\u8c61\u4e2d\u7684\u503c\uff1f<\/h3>\n<p>\u4e3a\u4e86\u83b7\u53d6\u5bf9\u8c61\u91cc\u7684\u503c\uff0c\u4f60\u9700\u8981\u5f15\u7528 key \u6765\u5bfb\u627e\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-plain_text\">console.log(person.firstName); \/\/ Parwinder\nconsole.log(person.lastName); \/\/ Bhagat\nconsole.log(person.age); \/\/ 33\nconsole.log(person.nicknames); \/\/ [&quot;Ricky&quot;, &quot;P&quot;]\nconsole.log(person.vehicles.car); \/\/ BMW X5\nYou can also refer\n<\/code><\/pre>\n<p>\u4f60\u540c\u6837\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u53f7\u5f62\u5f0f\u6765\u83b7\u53d6\u503c\uff1a<\/p>\n<pre><code class=\"language-plain_text\">console.log(person[&quot;age&quot;]); \/\/ 33\n<\/code><\/pre>\n<blockquote>\n<p>\u6ce8\u610f\uff1a\u70b9\u8bed\u6cd5\u662f\u9996\u9009\u5b58\u53d6\u65b9\u5f0f\uff0c\u9664\u975e\u8bbf\u95ee\u5c5e\u6027\u65f6\u5fc5\u987b\u4f7f\u7528\u53d8\u91cf\uff1akey \u5305\u542b\u5bfc\u81f4\u8bed\u6cd5\u9519\u8bef\u7684\u5b57\u7b26\u6216\u5173\u952e\u5b57\u3001\u4fdd\u7559\u5b57\u65f6\u3002<\/p>\n<\/blockquote>\n<pre><code class=\"language-plain_text\">console.log(person[&quot;my name&quot;]); \/\/ \n<\/code><\/pre>\n<h3><a id=\"%E5%A6%82%E4%BD%95%E4%B8%BA%E5%AF%B9%E8%B1%A1%E4%B8%AD%E7%9A%84key%E8%B5%8B%E5%80%BC%EF%BC%9F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5982\u4f55\u4e3a\u5bf9\u8c61\u4e2d\u7684 key \u8d4b\u503c\uff1f<\/h3>\n<p>\u5c31\u50cf\u7ed9\u53d8\u91cf\u8d4b\u503c\u4e00\u6837\uff0c\u4f60\u53ef\u4ee5\u7ed9\u5bf9\u8c61\u4e2d\u7684 key \u8d4b\u503c\u4efb\u4f55\u7c7b\u578b\u7684\u503c\u3002\u5728\u6211\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4e3a key \u8d4b\u503c\u4e86 \u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u6570\u7ec4\u548c\u5bf9\u8c61\u7c7b\u578b\u3002<\/p>\n<pre><code class=\"language-plain_text\">person.firstName = &quot;Julius&quot;;\nperson.lastName = &quot;Caesar&quot;;\nperson.age = 48;\nperson.vehicles = null;\n<\/code><\/pre>\n<h3><a id=\"%E5%AF%B9%E8%B1%A1%E4%B8%AD%E5%90%88%E6%B3%95%E7%9A%84key%E5%8C%85%E6%8B%AC%E5%93%AA%E4%BA%9B%EF%BC%9F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5bf9\u8c61\u4e2d\u5408\u6cd5\u7684 key \u5305\u62ec\u54ea\u4e9b\uff1f<\/h3>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<ol>\n<li>\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1a&quot;fristName&quot;<\/li>\n<li>\u5b57\u7b26\u4e32\u4e2d\u7684\u4e2d\u6a2a\u7ebf\uff0c\u4f8b\u5982\uff1a&quot;last-Name&quot;<\/li>\n<li>\u5b57\u7b26\u4e32\u4e2d\u7684\u7a7a\u683c\uff0c\u4f8b\u5982\uff1a&quot;middle name&quot;<\/li>\n<li>\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u503c\uff0c\u4f8b\u5982\uff1a&quot;007&quot;<\/li>\n<\/ol>\n<h3><a id=\"%E5%AF%B9%E8%B1%A1%E5%A6%82%E4%BD%95%E5%88%A0%E9%99%A4%E4%B8%80%E4%B8%AA%E5%B1%9E%E6%80%A7%EF%BC%9F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5bf9\u8c61\u5982\u4f55\u5220\u9664\u4e00\u4e2a\u5c5e\u6027\uff1f<\/h3>\n<p>\u4f7f\u7528 <strong>delete<\/strong> \u64cd\u4f5c\u7b26\uff1a<\/p>\n<pre><code class=\"language-plain_text\">delete(person.age);\nconsole.log(person.name); \/\/ Julius\nconsole.log(person.age); \/\/ undefined\n<\/code><\/pre>\n<h3><a id=\"%E5%AF%B9%E8%B1%A1%E7%9A%84key%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E8%B5%8B%E5%80%BC%E4%B8%BA%E5%87%BD%E6%95%B0%EF%BC%9F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5bf9\u8c61\u7684 key \u662f\u5426\u53ef\u4ee5\u8d4b\u503c\u4e3a\u51fd\u6570\uff1f<\/h3>\n<p>\u5f53\u7136\u53ef\u4ee5<\/p>\n<pre><code class=\"language-plain_text\">person.greeting = function(greeting = &quot;Hola&quot;) {\n    return `${greeting} ${this.firstName}`;\n};\nperson.greeting(&quot;Salute&quot;); \/\/ Salute Julius\nperson.greeting(); \/\/ Hola Julius\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1ahttps:\/\/dev.to\/bhagatparwinder\/what-are-objec&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[249,2,20,3],"tags":[6,91],"class_list":["post-1004","post","type-post","status-publish","format-standard","hentry","category-javascript","category-all","category-frontend","category-tech","tag-javascript","tag-object"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1004"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1004\/revisions"}],"predecessor-version":[{"id":1005,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1004\/revisions\/1005"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}