{"id":6172,"date":"2023-01-07T11:18:52","date_gmt":"2023-01-07T03:18:52","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6172"},"modified":"2023-01-07T11:18:52","modified_gmt":"2023-01-07T03:18:52","slug":"%e4%ba%86%e8%a7%a3node-js%e4%b8%ad%e7%9a%84%e5%85%a8%e5%b1%80%e5%b0%8d%e8%b1%a1globalobject","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/node-js\/%e4%ba%86%e8%a7%a3node-js%e4%b8%ad%e7%9a%84%e5%85%a8%e5%b1%80%e5%b0%8d%e8%b1%a1globalobject\/","title":{"rendered":"\u4e86\u89e3Node.js\u4e2d\u7684\u5168\u5c40\u5c0d\u8c61(GlobalObject)"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Node.js, \u5168\u5c40\u5c0d\u8c61, global object\"><\/p>\n<h1>\u5982\u4f55\u5728 Node.js \u4e2d\u4f7f\u7528\u5168\u5c40\u5c0d\u8c61(global object)\uff1f<\/h1>\n<p>Node.js \u662f\u4e00\u500b\u57fa\u65bc JavaScript \u7684\u958b\u6e90\u3001\u8de8\u5e73\u53f0\u7684 JavaScript \u74b0\u5883\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u958b\u767c\u670d\u52d9\u5668\u7aef\u548c\u7db2\u7d61\u61c9\u7528\u7a0b\u5e8f\u3002Node.js \u4e2d\u7684\u5168\u5c40\u5c0d\u8c61\u662f\u4e00\u500b\u7279\u6b8a\u7684\u5c0d\u8c61\uff0c\u5b83\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u88ab\u8a2a\u554f\uff0c\u800c\u4e0d\u9700\u8981\u4efb\u4f55\u7279\u6b8a\u7684\u8a2d\u7f6e\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5728 Node.js \u4e2d\u4f7f\u7528\u5168\u5c40\u5c0d\u8c61\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u5168\u5c40\u5c0d\u8c61\uff1f<\/h2>\n<p>\u5168\u5c40\u5c0d\u8c61\u662f\u4e00\u500b\u7279\u6b8a\u7684\u5c0d\u8c61\uff0c\u5b83\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u88ab\u8a2a\u554f\uff0c\u800c\u4e0d\u9700\u8981\u4efb\u4f55\u7279\u6b8a\u7684\u8a2d\u7f6e\u3002\u5728 Node.js \u4e2d\uff0c\u5168\u5c40\u5c0d\u8c61\u662f\u4e00\u500b\u7279\u6b8a\u7684\u5c0d\u8c61\uff0c\u5b83\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u88ab\u8a2a\u554f\uff0c\u800c\u4e0d\u9700\u8981\u4efb\u4f55\u7279\u6b8a\u7684\u8a2d\u7f6e\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528\u5168\u5c40\u5c0d\u8c61\uff1f<\/h2>\n<p>\u4f7f\u7528\u5168\u5c40\u5c0d\u8c61\u975e\u5e38\u7c21\u55ae\uff0c\u53ea\u9700\u8981\u5728\u7a0b\u5e8f\u4e2d\u5f15\u7528\u5b83\u5373\u53ef\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u8981\u4f7f\u7528\u5168\u5c40\u5c0d\u8c61\u4e2d\u7684 console \u5c0d\u8c61\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconsole.log('Hello World!');\n<\/pre>\n<p>\u9019\u6a23\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u4f7f\u7528 console \u5c0d\u8c61\uff0c\u800c\u4e0d\u9700\u8981\u4efb\u4f55\u7279\u6b8a\u7684\u8a2d\u7f6e\u3002<\/p>\n<h2>\u5168\u5c40\u5c0d\u8c61\u4e2d\u7684\u5176\u4ed6\u5c0d\u8c61<\/h2>\n<p>\u9664\u4e86 console \u5c0d\u8c61\u4e4b\u5916\uff0c\u5168\u5c40\u5c0d\u8c61\u4e2d\u9084\u6709\u8a31\u591a\u5176\u4ed6\u5c0d\u8c61\uff0c\u4f8b\u5982 process\u3001Buffer\u3001setTimeout \u7b49\u7b49\u3002<\/p>\n<p><!--more--><\/p>\n<h2>process \u5c0d\u8c61<\/h2>\n<p>process \u5c0d\u8c61\u662f Node.js \u4e2d\u6700\u91cd\u8981\u7684\u5c0d\u8c61\u4e4b\u4e00\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u8a2a\u554f\u548c\u63a7\u5236\u7576\u524d Node.js \u7a0b\u5e8f\u7684\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u7372\u53d6\u7576\u524d Node.js \u7a0b\u5e8f\u7684\u7248\u672c\uff1a<\/p>\n<pre class=\"brush: javascript\">\nconsole.log(process.version);\n<\/pre>\n<h2>Buffer \u5c0d\u8c61<\/h2>\n<p>Buffer \u5c0d\u8c61\u662f Node.js \u4e2d\u7684\u4e00\u500b\u5167\u7f6e\u5c0d\u8c61\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u5728\u5167\u5b58\u4e2d\u5b58\u5132\u4e8c\u9032\u5236\u6578\u64da\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u5275\u5efa\u4e00\u500b\u65b0\u7684 Buffer \u5c0d\u8c61\uff1a<\/p>\n<pre class=\"brush: javascript\">\nvar buf = new Buffer(10);\n<\/pre>\n<h2>setTimeout \u5c0d\u8c61<\/h2>\n<p>setTimeout \u5c0d\u8c61\u662f Node.js \u4e2d\u7684\u4e00\u500b\u5167\u7f6e\u5c0d\u8c61\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u5728\u6307\u5b9a\u7684\u6642\u9593\u5f8c\u57f7\u884c\u6307\u5b9a\u7684\u51fd\u6578\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u5728 5 \u79d2\u5f8c\u57f7\u884c\u4e00\u500b\u51fd\u6578\uff1a<\/p>\n<pre class=\"brush: javascript\">\nsetTimeout(function() {\n    console.log('Hello World!');\n}, 5000);\n<\/pre>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u8a73\u7d30\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Node.js \u4e2d\u4f7f\u7528\u5168\u5c40\u5c0d\u8c61\u3002\u6211\u5011\u9084\u4ecb\u7d39\u4e86\u5168\u5c40\u5c0d\u8c61\u4e2d\u7684\u4e00\u4e9b\u5176\u4ed6\u5c0d\u8c61\uff0c\u4f8b\u5982 process\u3001Buffer \u548c setTimeout \u7b49\u7b49\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981(Description):Node.js\u4e2d\u7684\u5168\u5c40\u5c0d\u8c61(GlobalObject)\u662f\u4e00\u500b\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u8a2a\u554f\u7684\u5c0d\u8c61\uff0c\u5b83\u53ef\u4ee5\u7528\u65bc\u5b58\u5132\u548c\u8a2a\u554f\u5168\u5c40\u8b8a\u91cf\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5168\u5c40\u51fd\u6578\uff0c\u4ee5\u4fbf\u5728Node.js\u61c9\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39Node.js\u4e2d\u7684\u5168\u5c40\u5c0d\u8c61\uff0c\u4ee5\u53ca\u5982\u4f55\u5728Node.js\u4e2d\u4f7f\u7528\u5b83\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":[193,192],"tags":[191,190],"class_list":["post-6172","post","type-post","status-publish","format-standard","hentry","category-node","category-node-js","tag-node","tag-node-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1By","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6172","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=6172"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6172\/revisions"}],"predecessor-version":[{"id":6173,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6172\/revisions\/6173"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}