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 +++++++++++----------- .../global_objects/object/create/index.html | 10 ++++----- .../object/defineproperties/index.html | 6 +++--- .../object/defineproperty/index.html | 24 +++++++++++----------- .../global_objects/object/fromentries/index.html | 8 ++++---- .../object/getownpropertydescriptor/index.html | 6 +++--- .../object/hasownproperty/index.html | 12 +++++------ .../reference/global_objects/object/index.html | 10 ++++----- .../reference/global_objects/object/is/index.html | 6 +++--- .../global_objects/object/issealed/index.html | 6 +++--- 10 files changed, 56 insertions(+), 56 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/object') 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
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html
index 073605d77f..671c542a48 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/create/index.html
@@ -20,7 +20,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/create
 
 

语法

-
Object.create(proto,[propertiesObject])
+
Object.create(proto,[propertiesObject])

参数

@@ -45,7 +45,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/create

下面的例子演示了如何使用Object.create()来实现类式继承。这是一个所有版本JavaScript都支持的单继承。

-
// Shape - 父类(superclass)
+
// Shape - 父类(superclass)
 function Shape() {
   this.x = 0;
   this.y = 0;
@@ -77,7 +77,7 @@ rect.move(1, 1); // Outputs, 'Shape moved.'

如果你希望能继承到多个对象,则可以使用混入的方式。

-
function MyClass() {
+
function MyClass() {
      SuperClass.call(this);
      OtherSuperClass.call(this);
 }
@@ -98,7 +98,7 @@ MyClass.prototype.myMethod = function() {
 
 

使用 Object.createpropertyObject参数

-
var o;
+
var o;
 
 // 创建一个原型为null的空对象
 o = Object.create(null);
@@ -167,7 +167,7 @@ o2 = Object.create({}, {
 
 

请注意,尽管在 ES5 中 Object.create支持设置为[[Prototype]]null,但因为那些ECMAScript5以前版本限制,此 polyfill 无法支持该特性。

-
if (typeof Object.create !== "function") {
+
if (typeof Object.create !== "function") {
     Object.create = function (proto, propertiesObject) {
         if (typeof proto !== 'object' && typeof proto !== 'function') {
             throw new TypeError('Object prototype may only be an Object: ' + proto);
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperties/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperties/index.html
index 483bcdf234..e4d9e9ef7a 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperties/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperties/index.html
@@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/defineProperties
 
 

语法

-
Object.defineProperties(objprops)
+
Object.defineProperties(objprops)

参数

@@ -63,7 +63,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/defineProperties

例子

-
var obj = {};
+
var obj = {};
 Object.defineProperties(obj, {
   'property1': {
     value: true,
@@ -80,7 +80,7 @@ Object.defineProperties(obj, {
 
 

假设一个原始的执行环境,所有的名称和属性都引用它们的初始值,Object.defineProperties几乎完全等同于(注意isCallable中的注释)以下JavaScript中的重新实现:

-
function defineProperties(obj, properties) {
+
function defineProperties(obj, properties) {
   function convertToDescriptor(desc) {
     function hasProperty(obj, prop) {
       return Object.prototype.hasOwnProperty.call(obj, prop);
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html
index c711f8b4d5..b37662d5ab 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html
@@ -25,7 +25,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/defineProperty
 
 

语法

-
Object.defineProperty(obj, prop, descriptor)
+
Object.defineProperty(obj, prop, descriptor)

参数

@@ -135,7 +135,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/defineProperty

记住,这些选项不一定是自身属性,也要考虑继承来的属性。为了确认保留这些默认值,在设置之前,可能要冻结 {{jsxref("Object.prototype")}},明确指定所有的选项,或者通过 {{jsxref("Object.create", "Object.create(null)")}} 将 {{jsxref("Object.prototype.__proto__", "__proto__")}} 属性指向 {{jsxref("null")}}。

-
// 使用 __proto__
+
// 使用 __proto__
 var obj = {};
 var descriptor = Object.create(null); // 没有继承的属性
 // 默认没有 enumerable,没有 configurable,没有 writable
@@ -178,7 +178,7 @@ Object.defineProperty(obj, "key", withValue("static"));
 
 

如果对象中不存在指定的属性,Object.defineProperty() 会创建这个属性。当描述符中省略某些字段时,这些字段将使用它们的默认值。

-
var o = {}; // 创建一个新对象
+
var o = {}; // 创建一个新对象
 
 // 在对象中添加一个属性与数据描述符的示例
 Object.defineProperty(o, "a", {
@@ -225,7 +225,7 @@ Object.defineProperty(o, "conflict", {
 
 

writable 属性设置为 false 时,该属性被称为“不可写的”。它不能被重新赋值。

-
var o = {}; // 创建一个新对象
+
var o = {}; // 创建一个新对象
 
 Object.defineProperty(o, 'a', {
   value: 37,
@@ -256,7 +256,7 @@ console.log(o.a); // logs 37. The assignment didn't work.
 
 

enumerable 定义了对象的属性是否可以在 {{jsxref("Statements/for...in", "for...in")}} 循环和 {{jsxref("Object.keys()")}} 中被枚举。

-
var o = {};
+
var o = {};
 Object.defineProperty(o, "a", { value : 1, enumerable: true });
 Object.defineProperty(o, "b", { value : 2, enumerable: false });
 Object.defineProperty(o, "c", { value : 3 }); // enumerable 默认为 false
@@ -296,7 +296,7 @@ p[Symbol.for('f')] // undefined

configurable 特性表示对象的属性是否可以被删除,以及除 valuewritable 特性外的其他特性是否可以被修改。

-
var o = {};
+
var o = {};
 Object.defineProperty(o, 'a', {
   get() { return 1; },
   configurable: false
@@ -329,7 +329,7 @@ console.log(o.a); // logs 1

考虑特性被赋予的默认特性值非常重要,通常,使用点运算符和 Object.defineProperty() 为对象的属性赋值时,数据描述符中的属性默认值是不同的,如下例所示。

-
var o = {};
+
var o = {};
 
 o.a = 1;
 // 等同于:
@@ -356,7 +356,7 @@ Object.defineProperty(o, "a", {
 
 

下面的例子展示了如何实现一个自存档对象。当设置temperature 属性时,archive 数组会收到日志条目。

-
function Archiver() {
+
function Archiver() {
   var temperature = null;
   var archive = [];
 
@@ -382,7 +382,7 @@ arc.getArchive(); // [{ val: 11 }, { val: 13 }]

下面这个例子中,getter 总是会返回一个相同的值。

-
var pattern = {
+
var pattern = {
     get: function () {
         return 'I alway return this string,whatever you have assigned';
     },
@@ -409,7 +409,7 @@ console.log(instance.myname);

如果访问者的属性是被继承的,它的 getset 方法会在子对象的属性被访问或者修改时被调用。如果这些方法用一个变量存值,该值会被所有对象共享。

-
function myclass() {
+
function myclass() {
 }
 
 var value;
@@ -430,7 +430,7 @@ console.log(b.x); // 1
 
 

这可以通过将值存储在另一个属性中解决。在 getset 方法中,this 指向某个被访问和修改属性的对象。

-
function myclass() {
+
function myclass() {
 }
 
 Object.defineProperty(myclass.prototype, "x", {
@@ -449,7 +449,7 @@ console.log(b.x); // undefined

不像访问者属性,值属性始终在对象自身上设置,而不是一个原型。然而,如果一个不可写的属性被继承,它仍然可以防止修改对象的属性。

-
function myclass() {
+
function myclass() {
 }
 
 myclass.prototype.x = 1;
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/fromentries/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/fromentries/index.html
index 80cb1de95a..d7b9c46865 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/object/fromentries/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/fromentries/index.html
@@ -13,7 +13,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/fromEntries
 
 

语法

-
Object.fromEntries(iterable);
+
Object.fromEntries(iterable);

参数

@@ -38,7 +38,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/fromEntries

通过 Object.fromEntries, 可以将 {{jsxref("Map")}} 转换为 {{jsxref("Object")}}:

-
const map = new Map([ ['foo', 'bar'], ['baz', 42] ]);
+
const map = new Map([ ['foo', 'bar'], ['baz', 42] ]);
 const obj = Object.fromEntries(map);
 console.log(obj); // { foo: "bar", baz: 42 }
 
@@ -47,7 +47,7 @@ console.log(obj); // { foo: "bar", baz: 42 }

通过 Object.fromEntries, 可以将 {{jsxref("Array")}} 转换为 {{jsxref("Object")}}:

-
const arr = [ ['0', 'a'], ['1', 'b'], ['2', 'c'] ];
+
const arr = [ ['0', 'a'], ['1', 'b'], ['2', 'c'] ];
 const obj = Object.fromEntries(arr);
 console.log(obj); // { 0: "a", 1: "b", 2: "c" }
 
@@ -56,7 +56,7 @@ console.log(obj); // { 0: "a", 1: "b", 2: "c" }

Object.fromEntries 是与 {{jsxref("Object.entries()")}} 相反的方法,用 数组处理函数 可以像下面这样转换对象:

-
const object1 = { a: 1, b: 2, c: 3 };
+
const object1 = { a: 1, b: 2, c: 3 };
 
 const object2 = Object.fromEntries(
   Object.entries(object1)
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptor/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptor/index.html
index a5b4088128..08874a06e8 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptor/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/getownpropertydescriptor/index.html
@@ -16,7 +16,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDes
 
 

语法

-
Object.getOwnPropertyDescriptor(obj, prop)
+
Object.getOwnPropertyDescriptor(obj, prop)

参数

@@ -54,7 +54,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDes

示例

-
var o, d;
+
var o, d;
 
 o = { get foo() { return 17; } };
 d = Object.getOwnPropertyDescriptor(o, "foo");
@@ -92,7 +92,7 @@ d = Object.getOwnPropertyDescriptor(o, "baz");
 
 

在 ES5 中,如果该方法的第一个参数不是对象(而是原始类型),那么就会产生出现 {{jsxref("TypeError")}}。而在 ES2015,第一个的参数不是对象的话就会被强制转换为对象。

-
Object.getOwnPropertyDescriptor('foo', 0);
+
Object.getOwnPropertyDescriptor('foo', 0);
 // 类型错误: "foo" 不是一个对象  // ES5 code
 
 Object.getOwnPropertyDescriptor('foo', 0);
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/hasownproperty/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/hasownproperty/index.html
index 70f5f307d6..b0c254e52a 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/object/hasownproperty/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/hasownproperty/index.html
@@ -22,7 +22,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
 
 

语法

-
obj.hasOwnProperty(prop)
+
obj.hasOwnProperty(prop)

参数

@@ -43,7 +43,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty

即使属性的值是 nullundefined,只要属性存在,hasOwnProperty 依旧会返回 true

-
o = new Object();
+
o = new Object();
 o.propOne = null;
 o.hasOwnProperty('propOne'); // 返回 true
 o.propTwo = undefined;
@@ -56,7 +56,7 @@ o.hasOwnProperty('propTwo'); // 返回 true
 
 

下面的例子检测了对象 o 是否含有自身属性 prop

-
o = new Object();
+
o = new Object();
 o.hasOwnProperty('prop'); // 返回 false
 o.prop = 'exists';
 o.hasOwnProperty('prop'); // 返回 true
@@ -68,7 +68,7 @@ o.hasOwnProperty('prop'); // 返回 false
 
 

下面的例子演示了 hasOwnProperty 方法对待自身属性和继承属性的区别:

-
o = new Object();
+
o = new Object();
 o.prop = 'exists';
 o.hasOwnProperty('prop');             // 返回 true
 o.hasOwnProperty('toString');         // 返回 false
@@ -79,7 +79,7 @@ o.hasOwnProperty('hasOwnProperty');   // 返回 false
 
 

下面的例子演示了如何在遍历一个对象的所有属性时忽略掉继承属性,注意这里 {{jsxref("Statements/for...in", "for...in")}}  循环只会遍历可枚举属性,所以不应该基于这个循环中没有不可枚举的属性而得出 hasOwnProperty 是严格限制于可枚举项目的(如同 {{jsxref("Object.getOwnPropertyNames()")}})。

-
var buz = {
+
var buz = {
   fog: 'stack'
 };
 
@@ -98,7 +98,7 @@ for (var name in buz) {
 
 

JavaScript 并没有保护 hasOwnProperty 这个属性名,因此,当某个对象可能自有一个占用该属性名的属性时,就需要使用外部的 hasOwnProperty 获得正确的结果:

-
var foo = {
+
var foo = {
   hasOwnProperty: function() {
     return false;
   },
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/index.html
index cd90b70b07..e143a7d49d 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/object/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/index.html
@@ -139,24 +139,24 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object
 
 

下面的例子将一个空的 Object 对象存到 o 中:

-
var o = new Object();
+
var o = new Object();
 
-
var o = new Object(undefined);
+
var o = new Object(undefined);
 
-
var o = new Object(null);
+
var o = new Object(null);
 

使用 Object 生成布尔对象

下面的例子将{{jsxref("Boolean")}} 对象存到 o 中:

-
// 等价于 o = new Boolean(true);
+
// 等价于 o = new Boolean(true);
 var o = new Object(true);
 
-
// 等价于 o = new Boolean(false);
+
// 等价于 o = new Boolean(false);
 var o = new Object(Boolean());
 
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/is/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/is/index.html index 9c3aff1abd..04a528b7b8 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/object/is/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/object/is/index.html @@ -17,7 +17,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/is

语法

-

Object.is(value1, value2);
+

Object.is(value1, value2);

参数

@@ -59,7 +59,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/is

Polyfill

-
if (!Object.is) {
+
if (!Object.is) {
   Object.is = function(x, y) {
     // SameValue algorithm
     if (x === y) { // Steps 1-5, 7-10
@@ -99,7 +99,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/is
 
 

使用 Object.is

-
Object.is('foo', 'foo');     // true
+
Object.is('foo', 'foo');     // true
 Object.is(window, window);   // true
 
 Object.is('foo', 'bar');     // false
diff --git a/files/zh-cn/web/javascript/reference/global_objects/object/issealed/index.html b/files/zh-cn/web/javascript/reference/global_objects/object/issealed/index.html
index d4bb3a438e..e6a895f345 100644
--- a/files/zh-cn/web/javascript/reference/global_objects/object/issealed/index.html
+++ b/files/zh-cn/web/javascript/reference/global_objects/object/issealed/index.html
@@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/isSealed
 
 

语法

-
Object.isSealed(obj)
+
Object.isSealed(obj)

参数

@@ -33,7 +33,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/isSealed

例子

-
// 新建的对象默认不是密封的.
+
// 新建的对象默认不是密封的.
 var empty = {};
 Object.isSealed(empty); // === false
 
@@ -72,7 +72,7 @@ Object.isFrozen(s3); // === true ,访问器属性不考虑可写不可写,只
 
 

在ES5中,如果这个方法的参数不是一个对象(一个原始类型),那么它会导致{{jsxref("TypeError")}}。在ES2015中,非对象参数将被视为是一个密封的普通对象,只返回true

-
Object.isSealed(1);
+
Object.isSealed(1);
 // TypeError: 1 is not an object (ES5 code)
 
 Object.isSealed(1);
-- 
cgit v1.2.3-54-g00ecf