-
Notifications
You must be signed in to change notification settings - Fork 0
API Object
对象创建、比较与复制
Object creation, comparison, and copying
Object 创建普通对象,并提供属性复制、相等比较和冻结工具。普通对象仍可直接使用对象字面量 {};当需要从原型派生时使用构造器。
Objectcreates ordinary objects and provides property-copying, equality, and freezing utilities. Use{}for ordinary literals; use the constructor when deriving from a prototype is required.
Parameters:
-
prototype
可选原型对象。Optional prototype object.
Returns
空对象,或派生自该原型的对象。
Empty object or an object derived from that prototype.
var base = { kind: "base" };
var item = new Object(base);
return item.kind;Parameters:
-
left、right
要进行严格比较的值。Values to compare strictly.
Returns
严格相等结果。
Strict equality result.
var value = {};
return Object.equal$(value, value); // trueParameters:
-
left、right
要比较的受支持值。Supported values to compare.
Returns
值相等结果。
Value-equality result.
return Object.equal("aurora", "aurora"); // trueParameters:
-
left、right
要递归比较的值。Values to compare recursively.
Returns
深度结构相等结果。
Deep structural-equality result.
return Object.deepEqual({ id: 1 }, { id: 1 }); // trueParameters:
-
target
接收属性的对象。Object receiving properties.
-
sources
一个或多个源对象。One or more source objects.
Returns
target 本身。
The same
target.
var target = { a: 1 };
Object.assign(target, { b: 2 });
return target.b; // 2Parameters:
-
value
要枚举的对象。Object to enumerate.
Returns
可枚举属性名数组。
Array of enumerable property names.
return Object.keys({ left: 1, right: 2 }).length; // 2Parameters:
-
value
要浅拷贝的值。Value to shallow-clone.
Returns
顶层对象副本。
Top-level copy.
var source = { nested: { value: 1 } };
var copy = Object.clone(source);
return copy.nested == source.nested; // trueParameters:
-
value
要深拷贝的值。Value to deep-clone.
Returns
独立的深度副本。
Independent deep copy.
var source = { nested: { value: 1 } };
var copy = Object.deepClone(source);
copy.nested.value = 2;
return source.nested.value; // 1Parameters:
-
value
要冻结的对象。Object to freeze.
Returns
null。
null.
用途
防止后续修改;在共享配置初始化完成后使用。
Prevents later mutation; use after shared configuration is initialized.
var settings = { enabled: true };
Object.freeze(settings);
return settings.enabled;Parameters:
-
prototype
候选原型。Candidate prototype.
Returns
当前实现不提供可依赖的有效返回值。
The current implementation does not provide a dependable effective return value.
状态
不要在生产代码中使用。
Do not use in production code.
var result = Object.extends({ kind: "base" });
return result; // do not rely on this resultParameters:
- 无。
None.
Returns
对象的字符串表示。
String representation of the object.
return ({ name: "Aurora" }).toString();Returns
可枚举成员数量。
Number of enumerable members.
return ({ first: 1, second: 2 }).length; // 2AuroraScript.JIT 4.0.0 · Documentation Home · Repository · MIT License