diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/object/assign/index.html')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/object/assign/index.html | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/assign/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/assign/index.html index 080c859773..c81cacda30 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/assign/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/assign/index.html @@ -18,11 +18,11 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign -<h2 id="Syntax" name="Syntax">语法</h2> +<h2 id="Syntax">语法</h2> <pre class="syntaxbox"><code>Object.assign(<var>target</var>, ...<var>sources</var>)</code></pre> -<h3 id="Parameters" name="Parameters">参数</h3> +<h3 id="Parameters">参数</h3> <dl> <dt><code>target</code></dt> @@ -31,7 +31,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign <dd>源对象。</dd> </dl> -<h3 id="Return_value" name="Return_value">返回值</h3> +<h3 id="Return_value">返回值</h3> <p>目标对象。</p> @@ -83,16 +83,16 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign }); }</pre> -<h2 id="Examples" name="Examples">示例</h2> +<h2 id="Examples">示例</h2> -<h3 id="Example_Cloning_an_object" name="Example:_Cloning_an_object">复制一个对象</h3> +<h3 id="Example_Cloning_an_object">复制一个对象</h3> <pre class="brush: js">const obj = { a: 1 }; const copy = Object.assign({}, obj); console.log(copy); // { a: 1 } </pre> -<h3 id="Deep_Clone" name="Deep_Clone">深拷贝问题</h3> +<h3 id="Deep_Clone">深拷贝问题</h3> <p>针对深拷贝,需要使用其他办法,因为 <code>Object.assign()</code>拷贝的是(可枚举)属性值。</p> @@ -137,7 +137,7 @@ function test() { test(); </pre> -<h3 id="Example_Merging_objects" name="Example:_Merging_objects">合并对象</h3> +<h3 id="Example_Merging_objects">合并对象</h3> <pre class="brush: js">const o1 = { a: 1 }; const o2 = { b: 2 }; @@ -159,7 +159,7 @@ console.log(obj); // { a: 1, b: 2, c: 3 }</pre> <p>属性被后续参数中具有相同属性的其他对象覆盖。</p> -<h3 id="Example_Symbol_properties" name="Example:_Symbol_properties">拷贝 symbol 类型的属性</h3> +<h3 id="Example_Symbol_properties">拷贝 symbol 类型的属性</h3> <pre class="brush: js">const o1 = { a: 1 }; const o2 = { [Symbol('foo')]: 2 }; @@ -168,7 +168,7 @@ const obj = Object.assign({}, o1, o2); console.log(obj); // { a : 1, [Symbol("foo")]: 2 } (cf. bug 1207182 on Firefox) Object.getOwnPropertySymbols(obj); // [Symbol(foo)]</pre> -<h3 id="Example_Only_own_enumerable_properties" name="Example:_Only_own_enumerable_properties">继承属性和不可枚举属性是不能拷贝的</h3> +<h3 id="Example_Only_own_enumerable_properties">继承属性和不可枚举属性是不能拷贝的</h3> <pre class="brush: js">const obj = Object.create({foo: 1}, { // foo 是个继承属性。 bar: { @@ -184,7 +184,7 @@ const copy = Object.assign({}, obj); console.log(copy); // { baz: 3 } </pre> -<h3 id="Example_Primitives" name="Example:_Primitives">原始类型会被包装为对象</h3> +<h3 id="Example_Primitives">原始类型会被包装为对象</h3> <pre class="brush: js">const v1 = "abc"; const v2 = true; @@ -196,7 +196,7 @@ const obj = Object.assign({}, v1, null, v2, undefined, v3, v4); // 注意,只有字符串的包装对象才可能有自身可枚举属性。 console.log(obj); // { "0": "a", "1": "b", "2": "c" }</pre> -<h3 id="Example_Exceptions" name="Example:_Exceptions">异常会打断后续拷贝任务</h3> +<h3 id="Example_Exceptions">异常会打断后续拷贝任务</h3> <pre class="brush: js">const target = Object.defineProperty({}, "foo", { value: 1, @@ -214,7 +214,7 @@ console.log(target.foo3); // undefined,异常之后 assign 方法就退出了 console.log(target.baz); // undefined,第三个源对象更是不会被拷贝到的。 </pre> -<h3 id="Example_Copy_accessors" name="Example:_Copy_accessors">拷贝访问器</h3> +<h3 id="Example_Copy_accessors">拷贝访问器</h3> <pre class="brush: js">const obj = { foo: 1, @@ -251,7 +251,7 @@ console.log(copy); // { foo:1, get bar() { return 2 } } </pre> -<h2 id="Polyfill" name="Polyfill">Polyfill</h2> +<h2 id="Polyfill">Polyfill</h2> <p>此{{Glossary("Polyfill","polyfill")}}不支持 symbol 属性,因为ES5 中根本没有 symbol :</p> @@ -285,7 +285,7 @@ console.log(copy); }); }</pre> -<h2 id="Specifications" name="Specifications">规范</h2> +<h2 id="Specifications">规范</h2> <table class="standard-table"> <tbody> @@ -307,11 +307,11 @@ console.log(copy); </tbody> </table> -<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容</h2> +<h2 id="Browser_compatibility">浏览器兼容</h2> <p>{{Compat("javascript.builtins.Object.assign")}}</p> -<h2 id="See_also" name="See_also">相关链接</h2> +<h2 id="See_also">相关链接</h2> <ul> <li>{{jsxref("Object.defineProperties()")}}</li> |