aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/object/defineproperty
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/object/defineproperty')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/object/defineproperty/index.html24
1 files changed, 12 insertions, 12 deletions
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
<h2 id="语法">语法</h2>
-<pre class="syntaxbox notranslate">Object.defineProperty(<var>obj</var>, <var>prop</var>, <var>descriptor</var>)</pre>
+<pre class="syntaxbox">Object.defineProperty(<var>obj</var>, <var>prop</var>, <var>descriptor</var>)</pre>
<h3 id="参数">参数</h3>
@@ -135,7 +135,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Object/defineProperty
<p>记住,这些选项不一定是自身属性,也要考虑继承来的属性。为了确认保留这些默认值,在设置之前,可能要冻结 {{jsxref("Object.prototype")}},明确指定所有的选项,或者通过 {{jsxref("Object.create", "Object.create(null)")}} 将 {{jsxref("Object.prototype.__proto__", "__proto__")}} 属性指向 {{jsxref("null")}}。</p>
-<pre class="brush: js notranslate">// 使用 __proto__
+<pre class="brush: js">// 使用 __proto__
var obj = {};
var descriptor = Object.create(null); // 没有继承的属性
// 默认没有 enumerable,没有 configurable,没有 writable
@@ -178,7 +178,7 @@ Object.defineProperty(obj, "key", withValue("static"));
<p>如果对象中不存在指定的属性,<code>Object.defineProperty()</code> 会创建这个属性。当描述符中省略某些字段时,这些字段将使用它们的默认值。</p>
-<pre class="brush: js notranslate">var o = {}; // 创建一个新对象
+<pre class="brush: js">var o = {}; // 创建一个新对象
// 在对象中添加一个属性与数据描述符的示例
Object.defineProperty(o, "a", {
@@ -225,7 +225,7 @@ Object.defineProperty(o, "conflict", {
<p>当 <code>writable</code> 属性设置为 <code>false</code> 时,该属性被称为“不可写的”。它不能被重新赋值。</p>
-<pre class="brush: js notranslate">var o = {}; // 创建一个新对象
+<pre class="brush: js">var o = {}; // 创建一个新对象
Object.defineProperty(o, 'a', {
value: 37,
@@ -256,7 +256,7 @@ console.log(o.a); // logs 37. The assignment didn't work.
<p><code>enumerable</code> 定义了对象的属性是否可以在 {{jsxref("Statements/for...in", "for...in")}} 循环和 {{jsxref("Object.keys()")}} 中被枚举。</p>
-<pre class="brush: js notranslate">var o = {};
+<pre class="brush: js">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</pre>
<p><code>configurable</code> 特性表示对象的属性是否可以被删除,以及除 <code>value</code> 和 <code>writable</code> 特性外的其他特性是否可以被修改。</p>
-<pre class="brush: js notranslate">var o = {};
+<pre class="brush: js">var o = {};
Object.defineProperty(o, 'a', {
get() { return 1; },
configurable: false
@@ -329,7 +329,7 @@ console.log(o.a); // logs 1</pre>
<p>考虑特性被赋予的默认特性值非常重要,通常,使用点运算符和 <code>Object.defineProperty()</code> 为对象的属性赋值时,数据描述符中的属性默认值是不同的,如下例所示。</p>
-<pre class="brush: js notranslate">var o = {};
+<pre class="brush: js">var o = {};
o.a = 1;
// 等同于:
@@ -356,7 +356,7 @@ Object.defineProperty(o, "a", {
<p>下面的例子展示了如何实现一个自存档对象。当设置<code>temperature</code> 属性时,<code>archive</code> 数组会收到日志条目。</p>
-<pre class="brush: js notranslate">function Archiver() {
+<pre class="brush: js">function Archiver() {
var temperature = null;
var archive = [];
@@ -382,7 +382,7 @@ arc.getArchive(); // [{ val: 11 }, { val: 13 }]</pre>
<p>下面这个例子中,getter 总是会返回一个相同的值。</p>
-<pre class="brush: js notranslate">var pattern = {
+<pre class="brush: js">var pattern = {
get: function () {
return 'I alway return this string,whatever you have assigned';
},
@@ -409,7 +409,7 @@ console.log(instance.myname);</pre>
<p>如果访问者的属性是被继承的,它的 <code>get</code> 和 <code>set</code> 方法会在子对象的属性被访问或者修改时被调用。如果这些方法用一个变量存值,该值会被所有对象共享。</p>
-<pre class="brush: js notranslate">function myclass() {
+<pre class="brush: js">function myclass() {
}
var value;
@@ -430,7 +430,7 @@ console.log(b.x); // 1
<p>这可以通过将值存储在另一个属性中解决。在 <code>get</code> 和 <code>set</code> 方法中,<code>this</code> 指向某个被访问和修改属性的对象。</p>
-<pre class="brush: js notranslate">function myclass() {
+<pre class="brush: js">function myclass() {
}
Object.defineProperty(myclass.prototype, "x", {
@@ -449,7 +449,7 @@ console.log(b.x); // undefined</pre>
<p>不像访问者属性,值属性始终在对象自身上设置,而不是一个原型。然而,如果一个不可写的属性被继承,它仍然可以防止修改对象的属性。</p>
-<pre class="brush: js notranslate">function myclass() {
+<pre class="brush: js">function myclass() {
}
myclass.prototype.x = 1;