{"id":5392,"date":"2023-01-05T12:35:28","date_gmt":"2023-01-05T04:35:28","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5392"},"modified":"2023-01-05T12:35:28","modified_gmt":"2023-01-05T04:35:28","slug":"%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e7%9a%84object%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/typescript\/%e4%ba%86%e8%a7%a3typescript%e4%b8%ad%e7%9a%84object%e5%8a%9f%e8%83%bd\/","title":{"rendered":"\u4e86\u89e3TypeScript\u4e2d\u7684Object\u529f\u80fd"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"TypeScript, object\"><\/p>\n<h1>\u4f7f\u7528 TypeScript \u4f86\u64cd\u4f5c Object<\/h1>\n<p>TypeScript \u662f\u4e00\u7a2e JavaScript \u7684\u8d85\u96c6\uff0c\u5b83\u64c1\u6709 JavaScript \u6240\u6709\u7684\u529f\u80fd\uff0c\u4e26\u4e14\u63d0\u4f9b\u4e86\u984d\u5916\u7684\u7279\u6027\uff0c\u4f8b\u5982\u985e\u578b\u6aa2\u67e5\uff0c\u6a21\u7d44\u5316\u7b49\u7b49\u3002\u5728 TypeScript \u4e2d\uff0cObject \u662f\u4e00\u7a2e\u57fa\u672c\u7684\u8cc7\u6599\u578b\u614b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4efb\u610f\u7a2e\u985e\u7684\u8cc7\u6599\uff0c\u4e26\u4e14\u53ef\u4ee5\u88ab\u7528\u4f86\u5efa\u7acb\u7269\u4ef6\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5728 TypeScript \u4e2d\uff0cObject \u662f\u4e00\u7a2e\u57fa\u672c\u7684\u8cc7\u6599\u578b\u614b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4efb\u610f\u7a2e\u985e\u7684\u8cc7\u6599\uff0c\u4e26\u4e14\u53ef\u4ee5\u88ab\u7528\u4f86\u5efa\u7acb\u7269\u4ef6\u3002Object \u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4efb\u610f\u7a2e\u985e\u7684\u8cc7\u6599\uff0c\u4f8b\u5982\u5b57\u4e32\u3001\u6578\u5b57\u3001\u9663\u5217\u3001\u51fd\u5f0f\u7b49\u7b49\u3002<\/p>\n<h2>\u5efa\u7acb Object<\/h2>\n<p>\u5728 TypeScript \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <span style=\"font-weight: bold;\">Object Literal<\/span> \u4f86\u5efa\u7acb Object\uff0cObject Literal \u662f\u4e00\u7a2e\u7c21\u55ae\u7684\u65b9\u5f0f\u4f86\u5efa\u7acb Object\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5efa\u7acb\u4e00\u500b\u7a7a\u7684 Object\uff0c\u6216\u662f\u5efa\u7acb\u4e00\u500b\u5305\u542b\u5c6c\u6027\u7684 Object\u3002<\/p>\n<pre class=\"brush: typescript\">\n\/\/ \u5efa\u7acb\u4e00\u500b\u7a7a\u7684 Object\nlet myObject = {};\n\n\/\/ \u5efa\u7acb\u4e00\u500b\u5305\u542b\u5c6c\u6027\u7684 Object\nlet myObject = {\n  name: 'John',\n  age: 30\n};\n<\/pre>\n<h2>\u4f7f\u7528 Object<\/h2>\n<p>Object \u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4efb\u610f\u7a2e\u985e\u7684\u8cc7\u6599\uff0c\u4f8b\u5982\u5b57\u4e32\u3001\u6578\u5b57\u3001\u9663\u5217\u3001\u51fd\u5f0f\u7b49\u7b49\u3002<\/p>\n<pre class=\"brush: typescript\">\n\/\/ \u5efa\u7acb\u4e00\u500b\u5305\u542b\u5c6c\u6027\u7684 Object\nlet myObject = {\n  name: 'John',\n  age: 30,\n  hobbies: ['Sports', 'Reading'],\n  sayHello: function() {\n    console.log('Hello!');\n  }\n};\n\n\/\/ \u4f7f\u7528 Object \u7684\u5c6c\u6027\nconsole.log(myObject.name); \/\/ John\nconsole.log(myObject.age); \/\/ 30\n\n\/\/ \u4f7f\u7528 Object \u7684\u51fd\u5f0f\nmyObject.sayHello(); \/\/ Hello!\n<\/pre>\n<h2>\u66f4\u65b0 Object<\/h2>\n<p>Object \u7684\u5c6c\u6027\u53ef\u4ee5\u88ab\u66f4\u65b0\uff0c\u53ef\u4ee5\u4f7f\u7528 <span style=\"font-weight: bold;\">dot notation<\/span> \u6216\u662f <span style=\"font-weight: bold;\">bracket notation<\/span> \u4f86\u66f4\u65b0 Object \u7684\u5c6c\u6027\u3002<\/p>\n<pre class=\"brush: typescript\">\n\/\/ \u5efa\u7acb\u4e00\u500b\u5305\u542b\u5c6c\u6027\u7684 Object\nlet myObject = {\n  name: 'John',\n  age: 30\n};\n\n\/\/ \u4f7f\u7528 dot notation \u66f4\u65b0 Object \u7684\u5c6c\u6027\nmyObject.name = 'Bob';\nmyObject.age = 40;\n\n\/\/ \u4f7f\u7528 bracket notation \u66f4\u65b0 Object \u7684\u5c6c\u6027\nmyObject['name'] = 'Alice';\nmyObject['age'] = 50;\n<\/pre>\n<h2>\u522a\u9664 Object<\/h2>\n<p>Object \u7684\u5c6c\u6027\u53ef\u4ee5\u88ab\u522a\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528 <span style=\"font-weight: bold;\">delete<\/span> \u95dc\u9375\u5b57\u4f86\u522a\u9664 Object \u7684\u5c6c\u6027\u3002<\/p>\n<pre class=\"brush: typescript\">\n\/\/ \u5efa\u7acb\u4e00\u500b\u5305\u542b\u5c6c\u6027\u7684 Object\nlet myObject = {\n  name: 'John',\n  age: 30\n};\n\n\/\/ \u4f7f\u7528 delete \u95dc\u9375\u5b57\u4f86\u522a\u9664 Object \u7684\u5c6c\u6027\ndelete myObject.name;\ndelete myObject.age;\n<\/pre>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728 TypeScript \u4e2d\uff0cObject \u662f\u4e00\u7a2e\u57fa\u672c\u7684\u8cc7\u6599\u578b\u614b\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4efb\u610f\u7a2e\u985e\u7684\u8cc7\u6599\uff0c\u4e26\u4e14\u53ef\u4ee5\u88ab\u7528\u4f86\u5efa\u7acb\u7269\u4ef6\u3002Object \u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u4efb\u610f\u7a2e\u985e\u7684\u8cc7\u6599\uff0c\u4f8b\u5982\u5b57\u4e32\u3001\u6578\u5b57\u3001\u9663\u5217\u3001\u51fd\u5f0f\u7b49\u7b49\u3002Object \u7684\u5c6c\u6027\u53ef\u4ee5\u88ab\u66f4\u65b0\u3001\u522a\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528 dot notation \u6216\u662f bracket notation \u4f86\u66f4\u65b0 Object \u7684\u5c6c\u6027\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 delete \u95dc\u9375\u5b57\u4f86\u522a\u9664 Object \u7684\u5c6c\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3TypeScript\u4e2d\u7684Object\u529f\u80fd\uff0cObject\u662fTypeScript\u4e2d\u6700\u57fa\u672c\u7684\u8cc7\u6599\u578b\u5225\uff0c\u53ef\u4ee5\u7528\u4f86\u5132\u5b58\u548c\u7ba1\u7406\u8cc7\u6599\uff0c\u672c\u6587\u5c07\u4ecb\u7d39Object\u7684\u57fa\u672c\u6982\u5ff5\u3001\u5efa\u7acb\u65b9\u5f0f\u3001\u5c6c\u6027\u548c\u65b9\u6cd5\u7b49\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[187],"tags":[186],"class_list":["post-5392","post","type-post","status-publish","format-standard","hentry","category-typescript","tag-typescript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1oY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5392"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5392\/revisions"}],"predecessor-version":[{"id":5393,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5392\/revisions\/5393"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}