{"id":52523,"date":"2024-12-03T12:03:29","date_gmt":"2024-12-03T04:03:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52523\/"},"modified":"2024-12-03T12:03:29","modified_gmt":"2024-12-03T04:03:29","slug":"javascript-%e5%af%b9%e8%b1%a1%e6%96%b9%e6%b3%95%e7%a4%ba%e4%be%8b-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52523\/","title":{"rendered":"JavaScript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>JavaScript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aJavaScript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b\u300b<\/span>\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732160163673eaaa3cb777.jpg\" class=\"aligncenter\" title=\"JavaScript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b\u63d2\u56fe\" alt=\"JavaScript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b\u63d2\u56fe\" \/><\/p>\n<h2> javascript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b\u3002 <\/h2>\n<ul>\n<li> <strong>object.keys(obj):<\/strong> \u8fd4\u56de\u5bf9\u8c61\u81ea\u5df1\u7684\u53ef\u679a\u4e3e\u5c5e\u6027\u540d\u79f0\uff08\u952e\uff09\u7684\u6570\u7ec4\u3002 <\/li>\n<\/ul>\n<pre>const obj = { a: 1, b: 2, c: 3 };\nconsole.log(object.keys(obj));\n\/\/ output: ['a', 'b', 'c']\n<\/pre>\n<ul>\n<li> <strong>object.values(obj):<\/strong> \u8fd4\u56de\u5bf9\u8c61\u81ea\u5df1\u7684\u53ef\u679a\u4e3e\u5c5e\u6027\u503c\u7684\u6570\u7ec4\u3002 <\/li>\n<\/ul>\n<pre>const obj = { a: 1, b: 2, c: 3 };\nconsole.log(object.values(obj));\n\/\/ output: [1, 2, 3]\n<\/pre>\n<ul>\n<li> <strong>object.entries(obj):<\/strong> \u8fd4\u56de\u5bf9\u8c61\u81ea\u5df1\u7684\u53ef\u679a\u4e3e\u5b57\u7b26\u4e32\u952e\u63a7\u5c5e\u6027 [key, value] \u5bf9\u7684\u6570\u7ec4\u3002 <\/li>\n<\/ul>\n<pre>const obj = { a: 1, b: 2, c: 3 };\nconsole.log(object.entries(obj));\n\/\/ output: [['a', 1], ['b', 2], ['c', 3]]\n<\/pre>\n<ul>\n<li> <strong>object.issealed(obj):<\/strong> \u5982\u679c\u5bf9\u8c61\u662f\u5bc6\u5c01\u7684\uff0c\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002 <\/li>\n<\/ul>\n<pre>const obj = object.seal({ a: 1 });\nconsole.log(object.issealed(obj));\n\/\/ output: true\n<\/pre>\n<ul>\n<li> <strong>object.assign(target, source):<\/strong> \u5c06\u6240\u6709\u53ef\u679a\u4e3e\u5c5e\u6027\u7684\u503c\u4ece\u4e00\u4e2a\u6216\u591a\u4e2a\u6e90\u5bf9\u8c61\u590d\u5236\u5230\u76ee\u6807\u5bf9\u8c61\u3002\u5b83\u8fd4\u56de\u76ee\u6807\u5bf9\u8c61\u3002 <\/li>\n<\/ul>\n<pre>const target = { a: 1 };\nconst source = { b: 2, c: 3 };\nconst result = object.assign(target, source);\nconsole.log(result);\n\/\/ output: { a: 1, b: 2, c: 3 }\n<\/pre>\n<ul>\n<li> <strong>object.freeze(obj):<\/strong> \u51bb\u7ed3\u5bf9\u8c61\uff0c\u9632\u6b62\u6dfb\u52a0\u65b0\u5c5e\u6027\u6216\u5220\u9664\u6216\u91cd\u65b0\u914d\u7f6e\u73b0\u6709\u5c5e\u6027\u3002 <\/li>\n<\/ul>\n<pre>const obj = { name: 'khabib' };\nobject.freeze(obj);\nobj.name = 'bob'; \/\/ this won't change the value\nconsole.log(obj.name); \/\/ output: 'khabib'\n<\/pre>\n<ul>\n<li> <strong>object.seal(obj):<\/strong> \u5bc6\u5c01\u5bf9\u8c61\uff0c\u9632\u6b62\u6dfb\u52a0\u65b0\u5c5e\u6027\uff0c\u4f46\u5141\u8bb8\u4fee\u6539\u73b0\u6709\u5c5e\u6027\u3002 <\/li>\n<\/ul>\n<pre>const obj = { name: 'alice' };\nobject.seal(obj);\nobj.name = 'bob'; \/\/ this will update the value\nobj.age = 25; \/\/ this won't add a new property\nconsole.log(obj); \/\/ output: { name: 'bob' }\n<\/pre>\n<ul>\n<li> <strong>object.create(proto):<\/strong> \u4f7f\u7528\u6307\u5b9a\u7684\u539f\u578b\u5bf9\u8c61\u548c\u5c5e\u6027\u521b\u5efa\u4e00\u4e2a\u65b0\u5bf9\u8c61\u3002 <\/li>\n<\/ul>\n<pre>const person = {greet() {console.log('hello!');}};\nconst student = object.create(person);\nstudent.greet();\n\/\/ output: 'hello!'\n<\/pre>\n<ul>\n<li> <strong>object.defineproperty(obj, prop, detector):<\/strong> \u76f4\u63a5\u5728\u5bf9\u8c61\u4e0a\u5b9a\u4e49\u65b0\u5c5e\u6027\u6216\u4fee\u6539\u73b0\u6709\u5c5e\u6027\u3002 <\/li>\n<\/ul>\n<pre>const obj = {};\nobject.defineproperty(obj, 'name', {\nvalue: 'alice',\nwritable: false });\nconsole.log(obj.name); \/\/ 'alice'\n<\/pre>\n<ul>\n<li> <strong>object.defineproperties(obj, props):<\/strong> \u5b9a\u4e49\u591a\u4e2a\u65b0\u5c5e\u6027\u6216\u4fee\u6539\u5bf9\u8c61\u7684\u73b0\u6709\u5c5e\u6027\u3002 <\/li>\n<\/ul>\n<pre>const obj = {};\nobject.defineproperties(obj, {\nname: { value: 'cormier', writable: false },\nage: { value: 30, writable: true } });\nconsole.log(obj.name); \/\/ 'cormier'\n<\/pre>\n<ul>\n<li> <strong>object.isextensible(obj):<\/strong> \u786e\u5b9a\u5bf9\u8c61\u662f\u5426\u53ef\u6269\u5c55\uff08\u5373\u662f\u5426\u53ef\u4ee5\u6dfb\u52a0\u65b0\u5c5e\u6027\uff09\u3002 <\/li>\n<\/ul>\n<pre>const obj = {};\nconsole.log(object.isextensible(obj)); \/\/ true\nobject.preventextensions(obj);\nconsole.log(object.isextensible(obj)); \/\/ false\n<\/pre>\n<ul>\n<li> <strong>object.isfrozen(obj):<\/strong> \u786e\u5b9a\u5bf9\u8c61\u662f\u5426\u88ab\u51bb\u7ed3\uff08\u5373\u4e0d\u53ef\u6269\u5c55\u4e14\u6240\u6709\u5c5e\u6027\u4e0d\u53ef\u5199\uff09\u3002 <\/li>\n<\/ul>\n<pre>const obj = object.freeze({ name: 'gregor' });\nconsole.log(object.isfrozen(obj));\n\/\/ output: true\n<\/pre>\n<ul>\n<li> <strong>object.hasown(obj, prop):<\/strong> \u5982\u679c\u6307\u5b9a\u5bf9\u8c61\u5c06\u6307\u5b9a\u5c5e\u6027\u4f5c\u4e3a\u5176\u81ea\u5df1\u7684\u5c5e\u6027\uff0c\u5219\u8fd4\u56de true\uff0c\u5373\u4f7f\u8be5\u5c5e\u6027\u7684\u503c\u672a\u5b9a\u4e49\u3002 <\/li>\n<\/ul>\n<pre>const obj = { name: 'alice' };\nconsole.log(object.hasown(obj, 'name')); \/\/ true\nconsole.log(object.hasown(obj, 'age')); \/\/ false\n<\/pre>\n<ul>\n<li> <strong>object.hasownproperty(prop):<\/strong> \u786e\u5b9a\u5bf9\u8c61\u662f\u5426\u5305\u542b\u6307\u5b9a\u5c5e\u6027\u4f5c\u4e3a\u8be5\u5bf9\u8c61\u7684\u76f4\u63a5\u5c5e\u6027\uff0c\u800c\u4e0d\u662f\u901a\u8fc7\u539f\u578b\u94fe\u7ee7\u627f\u3002 <\/li>\n<\/ul>\n<pre>const obj = { name: 'alice' };\nconsole.log(obj.hasownproperty('name')); \/\/ true\nconsole.log(obj.hasownproperty('age')); \/\/ false\n<\/pre>\n<ul>\n<li> <strong>object.preventextensions(obj):<\/strong> \u9632\u6b62\u5c06\u65b0\u5c5e\u6027\u6dfb\u52a0\u5230\u5bf9\u8c61\u4e2d\u3002 <\/li>\n<\/ul>\n<pre>const obj = {};\nobject.preventextensions(obj);\nobj.name = 'khabib'; \/\/ won't be added\nconsole.log(obj); \/\/ {}\n<\/pre>\n<ul>\n<li> <strong>object.setprototypeof(obj, proto):<\/strong> \u8bbe\u7f6e\u6307\u5b9a\u5bf9\u8c61\u7684\u539f\u578b\uff08\u5185\u90e8 [[prototype]] \u5c5e\u6027\uff09\u3002 <\/li>\n<\/ul>\n<pre>const proto = { greet() {console.log('hello!');}};\nconst obj = {};\nobject.setprototypeof(obj, proto);\nobj.greet(); \/\/ 'hello!'\n<\/pre>\n<ul>\n<li> <strong>object.fromentries(iterable):<\/strong> \u5c06\u952e\u503c\u5bf9\u5217\u8868\u8f6c\u6362\u4e3a\u5bf9\u8c61\u3002 <\/li>\n<\/ul>\n<pre>const entries = [['name', 'rock'], ['age', 35]];\nconst obj = object.fromentries(entries);\nconsole.log(obj); \/\/ { name: 'rock', age: 35 }\n<\/pre>\n<ul>\n<li> <strong>object.getprototypeof(obj)<\/strong>\uff1a\u8fd4\u56de\u6307\u5b9a\u5bf9\u8c61\u7684\u539f\u578b\uff08\u5185\u90e8 [[prototype]] \u5c5e\u6027\uff09\u3002 <\/li>\n<\/ul>\n<pre>const obj = {};\nconst proto = object.getprototypeof(obj);\nconsole.log(proto === object.prototype); \/\/ true\n<\/pre>\n<ul>\n<li> <strong>object.getownpropertysymbols(obj):<\/strong> \u8fd4\u56de\u5728\u5bf9\u8c61\u4e0a\u627e\u5230\u7684\u6240\u6709\u7b26\u53f7\u5c5e\u6027\u7684\u6570\u7ec4\u3002 <\/li>\n<\/ul>\n<pre>const symbol = symbol('id');\nconst obj = { [symbol]: 123 };\nconst symbols = object.getownpropertysymbols(obj);\nconsole.log(symbols); \/\/ [symbol(id)]\nconsole.log(obj[symbols[0]]); \/\/ 123\n<\/pre>\n<ul>\n<li> <strong>object.getownpropertydescriptor(obj, prop):<\/strong> \u8fd4\u56de\u7ed9\u5b9a\u5bf9\u8c61\u7684\u7279\u5b9a\u5c5e\u6027\u7684\u5c5e\u6027\u63cf\u8ff0\u7b26\u3002 <\/li>\n<\/ul>\n<pre>const obj = { name: 'alice', age: 26 };\nconst descriptor = object.getownpropertydescriptor(obj, 'name');\nconsole.log(descriptor);\n\/\/ output: { configurable: true, enumerable: true, value: \"alice\", writable: true }\n<\/pre>\n<ul>\n<li> <strong>object.getownpropertynames(obj):<\/strong> \u8fd4\u56de\u5728\u5bf9\u8c61\u4e0a\u627e\u5230\u7684\u6240\u6709\u5c5e\u6027\uff08\u5305\u62ec\u4e0d\u53ef\u679a\u4e3e\u5c5e\u6027\uff09\u7684\u6570\u7ec4\u3002 <\/li>\n<\/ul>\n<p> 9688635538\u200b\u200b35 <\/p>\n<ul>\n<li> <strong>object.is(value1, value2):<\/strong> \u6bd4\u8f83\u4e24\u4e2a\u503c\u662f\u5426\u76f8\u540c\u3002 <\/li>\n<\/ul>\n<pre>console.log(object.is('foo', 'foo')); \/\/ true\nconsole.log(object.is({}, {})); \/\/ false\n<\/pre>\n<ul>\n<li> <strong>object.getownpropertydescriptors(obj):<\/strong> \u8fd4\u56de\u5bf9\u8c61\u7684\u6240\u6709\u81ea\u6709\u5c5e\u6027\u63cf\u8ff0\u7b26\u3002 <\/li>\n<\/ul>\n<pre>const obj = { name: 'Khabib', age: 28 };\nconst descriptors = Object.getOwnPropertyDescriptors(obj);\nconsole.log(descriptors);\n\/\/ Output: {\nage: {\nconfigurable: true,\nenumerable: true,\nvalue: 28,\nwritable: true },\nname: {\n  configurable: true,\n  enumerable: true,\n  value: \"Khabib\",\n  writable: true\n }\n}\n<\/pre>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aJavaScript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664    <\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   Biomejs\uff0c\u4e00\u4e2a\u7528\u4e8e\u683c\u5f0f\u5316\u548c\u68c0\u67e5 Web \u9879\u76ee\u7684\u5de5\u5177\u94fe\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b \u6536\u85cf \u6700\u8fd1\u53d1\u73b0\u4e0d\u5c11\u5c0f\u4f19\u4f34\u90fd\u5bf9\u6587\u7ae0\u5f88\u611f\u5174\u8da3\uff0c\u6240\u4ee5\u4eca\u5929\u7ee7\u7eed\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\uff0c\u672c\u6587\u300aJavaScript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b\u300b\u4e3b\u8981\u5185\u5bb9\u6d89\u53ca\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01\u5f53\u7136\u5982\u679c\u9605\u8bfb\u672c\u6587\u65f6\u5b58\u5728\u4e0d\u540c\u60f3\u6cd5\uff0c\u53ef\u4ee5\u5728\u8bc4\u8bba\u4e2d\u8868\u8fbe\uff0c\u4f46\u662f\u8bf7\u52ff\u4f7f\u7528\u8fc7\u6fc0\u7684\u63aa\u8f9e~ javascript \u5bf9\u8c61\u65b9\u6cd5\u793a\u4f8b\u3002 object.keys(obj): \u8fd4\u56de\u5bf9\u8c61\u81ea\u5df1\u7684\u53ef\u679a\u4e3e\u5c5e\u6027\u540d\u79f0\uff08\u952e\uff09\u7684\u6570\u7ec4\u3002 const obj = { a: 1, b: 2, c: 3 }; console.log(object.keys(obj)); \/\/ output: [&#8216;a&#8217;, &#8216;b&#8217;, &#8216;c&#8217;] object.values(obj): \u8fd4\u56de\u5bf9\u8c61\u81ea\u5df1\u7684\u53ef\u679a\u4e3e\u5c5e\u6027\u503c\u7684\u6570\u7ec4\u3002 const obj = { a: 1, b: 2, c: 3 }; console.log(object.values(obj)); \/\/ output: [1, 2, 3] object.entries(obj): \u8fd4\u56de\u5bf9\u8c61\u81ea\u5df1\u7684\u53ef\u679a\u4e3e\u5b57\u7b26\u4e32\u952e\u63a7\u5c5e\u6027 [key, value] \u5bf9\u7684\u6570\u7ec4\u3002 const obj = { a: [&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-52523","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52523","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=52523"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52523\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}