{"id":3188,"date":"2024-11-10T14:08:34","date_gmt":"2024-11-10T06:08:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3188\/"},"modified":"2024-11-10T14:08:34","modified_gmt":"2024-11-10T06:08:34","slug":"js%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8%e5%af%b9%e8%b1%a1%e5%86%85%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3188\/","title":{"rendered":"js\u5982\u4f55\u8c03\u7528\u5bf9\u8c61\u5185\u65b9\u6cd5"},"content":{"rendered":"<blockquote><p>\n  \u5728 javascript \u4e2d\u8c03\u7528\u5bf9\u8c61\u5185\u7684\u65b9\u6cd5\uff0c\u9700\u5b8c\u6210\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa\u5bf9\u8c61\uff0c\u5305\u542b\u8981\u8c03\u7528\u7684\u65b9\u6cd5\u3002\u4f7f\u7528\u70b9\u8fd0\u7b97\u7b26\u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5\u3002\u4f7f\u7528\u5706\u62ec\u53f7\u8fd0\u884c\u5bf9\u8c61\u65b9\u6cd5\u3002\u8f93\u51fa\u7ed3\u679c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110806370565943.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u8c03\u7528\u5bf9\u8c61\u5185\u65b9\u6cd5\u63d2\u56fe\" alt=\"js\u5982\u4f55\u8c03\u7528\u5bf9\u8c61\u5185\u65b9\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 JavaScript \u4e2d\u8c03\u7528\u5bf9\u8c61\u5185\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u4f7f\u7528 JavaScript \u8c03\u7528\u5bf9\u8c61\u5185\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u5305\u542b\u4f60\u8981\u8c03\u7528\u7684\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>const person = {\n  name: \"John Doe\",\n  age: 30,\n  greet: function() {\n    console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);\n  }\n};<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. \u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5<\/strong><\/p>\n<p>\u8981\u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5\uff0c\u8bf7\u4f7f\u7528\u70b9\uff08.\uff09\u8fd0\u7b97\u7b26\u3002\u4f8b\u5982\uff0c\u8981\u8bbf\u95ee person \u5bf9\u8c61\u4e2d\u7684 greet \u65b9\u6cd5\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>person.greet();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>3. \u8fd0\u884c\u5bf9\u8c61\u65b9\u6cd5<\/strong><\/p>\n<p>\u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5\u540e\uff0c\u4f7f\u7528\u5706\u62ec\u53f7 () \u6765\u8fd0\u884c\u5b83\u3002\u4f8b\u5982\uff0c\u8981\u8fd0\u884c greet \u65b9\u6cd5\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>person.greet();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>4. \u8f93\u51fa\u7ed3\u679c<\/strong><\/p>\n<p>greet \u65b9\u6cd5\u4f1a\u8f93\u51fa\u4e00\u4e2a\u6d88\u606f\u5230\u63a7\u5236\u53f0\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 console.log() \u65b9\u6cd5\u6765\u67e5\u770b\u8f93\u51fa\u3002<\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5728 JavaScript \u4e2d\u8c03\u7528\u5bf9\u8c61\u5185\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a person \u5bf9\u8c61\nconst person = {\n  name: \"John Doe\",\n  age: 30,\n  greet: function() {\n    console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);\n  }\n};\n\n\/\/ \u8bbf\u95ee greet \u65b9\u6cd5\nconst greetFunction = person.greet;\n\n\/\/ \u8fd0\u884c greet \u65b9\u6cd5\ngreetFunction();\n\n\/\/ \u8f93\u51fa\u7ed3\u679c\n\/\/ Hello, my name is John Doe and I am 30 years old.<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u8be5\u5bf9\u8c61\u5305\u542b\u8981\u8c03\u7528\u7684\u65b9\u6cd5\uff0c\u5426\u5219\u4f1a\u53d1\u751f\u9519\u8bef\u3002<\/li>\n<li>this \u5173\u952e\u5b57\u7528\u4e8e\u5f15\u7528\u8c03\u7528\u65b9\u6cd5\u7684\u5bf9\u8c61\u3002<\/li>\n<li>\u53ef\u4ee5\u5c06\u5bf9\u8c61\u65b9\u6cd5\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\uff0c\u4ee5\u4fbf\u4ee5\u540e\u91cd\u7528\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u8c03\u7528\u5bf9\u8c61\u5185\u65b9\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 javascript \u4e2d\u8c03\u7528\u5bf9\u8c61\u5185\u7684\u65b9\u6cd5\uff0c\u9700\u5b8c\u6210\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u521b\u5efa\u5bf9\u8c61\uff0c\u5305\u542b\u8981\u8c03\u7528\u7684\u65b9\u6cd5\u3002\u4f7f\u7528\u70b9\u8fd0\u7b97\u7b26\u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5\u3002\u4f7f\u7528\u5706\u62ec\u53f7\u8fd0\u884c\u5bf9\u8c61\u65b9\u6cd5\u3002\u8f93\u51fa\u7ed3\u679c\u3002 \u5982\u4f55\u5728 JavaScript \u4e2d\u8c03\u7528\u5bf9\u8c61\u5185\u7684\u65b9\u6cd5 \u4f7f\u7528 JavaScript \u8c03\u7528\u5bf9\u8c61\u5185\u7684\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61 \u9996\u5148\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u5305\u542b\u4f60\u8981\u8c03\u7528\u7684\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a const person = { name: &#8220;John Doe&#8221;, age: 30, greet: function() { console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`); } }; \u767b\u5f55\u540e\u590d\u5236 2. \u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5 \u8981\u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5\uff0c\u8bf7\u4f7f\u7528\u70b9\uff08.\uff09\u8fd0\u7b97\u7b26\u3002\u4f8b\u5982\uff0c\u8981\u8bbf\u95ee person \u5bf9\u8c61\u4e2d\u7684 greet \u65b9\u6cd5\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a person.greet(); \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 3. \u8fd0\u884c\u5bf9\u8c61\u65b9\u6cd5 \u8bbf\u95ee\u5bf9\u8c61\u65b9\u6cd5\u540e\uff0c\u4f7f\u7528\u5706\u62ec\u53f7 () \u6765\u8fd0\u884c\u5b83\u3002\u4f8b\u5982\uff0c\u8981\u8fd0\u884c greet \u65b9\u6cd5\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3188","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3188"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3188\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}