From 01b0e12ba27b5069248fd09235e9a7143915ee30 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:02:49 +0800 Subject: remove `notranslate` class in zh-CN --- .../global_objects/object/assign/index.html | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/object/assign') 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 1e1080be00..080c859773 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 @@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign

语法

-
Object.assign(target, ...sources)
+
Object.assign(target, ...sources)

参数

@@ -53,7 +53,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign

这个 polyfill 不支持 symbol 属性, 由于 ES5 中本来就不存在 symbols :

-
if (typeof Object.assign !== 'function') {
+
if (typeof Object.assign !== 'function') {
   // Must be writable: true, enumerable: false, configurable: true
   Object.defineProperty(Object, "assign", {
     value: function assign(target, varArgs) { // .length of function is 2
@@ -87,7 +87,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/assign
 
 

复制一个对象

-
const obj = { a: 1 };
+
const obj = { a: 1 };
 const copy = Object.assign({}, obj);
 console.log(copy); // { a: 1 }
 
@@ -98,7 +98,7 @@ console.log(copy); // { a: 1 }

假如源值是一个对象的引用,它仅仅会复制其引用值。

-
const log = console.log;
+
const log = console.log;
 
 function test() {
   'use strict';
@@ -139,7 +139,7 @@ test();
 
 

合并对象

-
const o1 = { a: 1 };
+
const o1 = { a: 1 };
 const o2 = { b: 2 };
 const o3 = { c: 3 };
 
@@ -150,7 +150,7 @@ console.log(o1);  // { a: 1, b: 2, c: 3 }, 注意目标对象自身也会改变
 
 

合并具有相同属性的对象

-
const o1 = { a: 1, b: 1, c: 1 };
+
const o1 = { a: 1, b: 1, c: 1 };
 const o2 = { b: 2, c: 2 };
 const o3 = { c: 3 };
 
@@ -161,7 +161,7 @@ console.log(obj); // { a: 1, b: 2, c: 3 }

拷贝 symbol 类型的属性

-
const o1 = { a: 1 };
+
const o1 = { a: 1 };
 const o2 = { [Symbol('foo')]: 2 };
 
 const obj = Object.assign({}, o1, o2);
@@ -170,7 +170,7 @@ Object.getOwnPropertySymbols(obj); // [Symbol(foo)]

继承属性和不可枚举属性是不能拷贝的

-
const obj = Object.create({foo: 1}, { // foo 是个继承属性。
+
const obj = Object.create({foo: 1}, { // foo 是个继承属性。
     bar: {
         value: 2  // bar 是个不可枚举属性。
     },
@@ -186,7 +186,7 @@ console.log(copy); // { baz: 3 }
 
 

原始类型会被包装为对象

-
const v1 = "abc";
+
const v1 = "abc";
 const v2 = true;
 const v3 = 10;
 const v4 = Symbol("foo")
@@ -198,7 +198,7 @@ console.log(obj); // { "0": "a", "1": "b", "2": "c" }

异常会打断后续拷贝任务

-
const target = Object.defineProperty({}, "foo", {
+
const target = Object.defineProperty({}, "foo", {
     value: 1,
     writable: false
 }); // target 的 foo 属性是个只读属性。
@@ -216,7 +216,7 @@ console.log(target.baz);  // undefined,第三个源对象更是不会被拷贝
 
 

拷贝访问器

-
const obj = {
+
const obj = {
   foo: 1,
   get bar() {
     return 2;
@@ -255,7 +255,7 @@ console.log(copy);
 
 

此{{Glossary("Polyfill","polyfill")}}不支持 symbol 属性,因为ES5 中根本没有 symbol :

-
if (typeof Object.assign != 'function') {
+
if (typeof Object.assign != 'function') {
   // Must be writable: true, enumerable: false, configurable: true
   Object.defineProperty(Object, "assign", {
     value: function assign(target, varArgs) { // .length of function is 2
-- 
cgit v1.2.3-54-g00ecf