语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -2,7 +2,7 @@
<div></div>
<p><strong><code>Object.getOwnPropertyNames()</code></strong>方法返回一个由指定对象的所有自身属性的属性名包括不可枚举属性但不包括Symbol值作为名称的属性组成的数组。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox">Object.getOwnPropertyNames(<em>obj</em>)</pre>
<pre><code class="language-javascript">Object.getOwnPropertyNames(<em>obj</em>)</code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code>obj</code></dt>
@@ -14,7 +14,7 @@
<p><code>Object.getOwnPropertyNames()</code> 返回一个数组,该数组对元素是 <code>obj</code>自身拥有的枚举或不可枚举属性名称字符串。 数组中枚举属性的顺序与通过 <a href="Reference/Statements/for...in" title="for...in语句以任意顺序遍历一个对象的可枚举属性。对于每个不同的属性语句都会被执行。"><code>for...in</code></a> 循环(或 <a href="Reference/Global_Objects/Object/keys" title="Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组,数组中属性名的排列顺序和使用 for...in 循环遍历该对象时返回的顺序一致 。"><code>Object.keys</code></a>)迭代该对象属性时一致。数组中不可枚举属性的顺序未定义。</p>
<h2 id="示例">示例</h2>
<h3 id="使用_Object.getOwnPropertyNames()">使用 <code>Object.getOwnPropertyNames()</code></h3>
<pre class="brush: js">var arr = ["a", "b", "c"];
<pre><code class="language-javascript">var arr = ["a", "b", "c"];
console.log(Object.getOwnPropertyNames(arr).sort()); // ["0", "1", "2", "length"]
// 类数组对象
@@ -40,10 +40,10 @@ var my_obj = Object.create({}, {
my_obj.foo = 1;
console.log(Object.getOwnPropertyNames(my_obj).sort()); // ["foo", "getFoo"]
</pre>
</code></pre>
<p>如果你只要获取到可枚举属性,查看<a href="Reference/Global_Objects/Object/keys" title="Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组,数组中属性名的排列顺序和使用 for...in 循环遍历该对象时返回的顺序一致 。"><code>Object.keys</code></a>或用<a href="Reference/Statements/for...in" title="for...in语句以任意顺序遍历一个对象的可枚举属性。对于每个不同的属性语句都会被执行。"><code>for...in</code></a>循环(还会获取到原型链上的可枚举属性,不过可以使用<a href="Reference/Global_Objects/Object/hasOwnProperty" title="hasOwnProperty() 方法会返回一个布尔值,指示对象自身属性中是否具有指定的属性"><code>hasOwnProperty()</code></a>方法过滤掉)。</p>
<p>下面的例子演示了该方法不会获取到原型链上的属性:</p>
<pre class="brush: js">function ParentClass() {}
<pre><code class="language-javascript">function ParentClass() {}
ParentClass.prototype.inheritedMethod = function() {};
function ChildClass() {
@@ -59,10 +59,10 @@ console.log(
  new ChildClass() // ["prop", "method"]
  )
);
</pre>
</code></pre>
<h3 id="只获取不可枚举的属性">只获取不可枚举的属性</h3>
<p>下面的例子使用了 <a href="Reference/Global_Objects/Array/filter" title="filter() 方法创建一个新数组, 其包含通过所提供函数实现的测试的所有元素。"><code>Array.prototype.filter()</code></a> 方法,从所有的属性名数组(使用<code>Object.getOwnPropertyNames()</code>方法获得)中去除可枚举的属性(使用<a href="Reference/Global_Objects/Object/keys" title="Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组,数组中属性名的排列顺序和使用 for...in 循环遍历该对象时返回的顺序一致 。"><code>Object.keys()</code></a>方法获得),剩余的属性便是不可枚举的属性了:</p>
<pre class="brush: js">var target = myObject;
<pre><code class="language-javascript">var target = myObject;
var enum_and_nonenum = Object.getOwnPropertyNames(target);
var enum_only = Object.keys(target);
var nonenum_only = enum_and_nonenum.filter(function(key) {
@@ -76,16 +76,16 @@ var nonenum_only = enum_and_nonenum.filter(function(key) {
    }
});
console.log(nonenum_only);</pre>
<pre>注:<a href="https://developer.mozilla.orgReference/Global_Objects/Array/filter">Array.filter(filt_func)方法</a>创建一个新数组, 其包含通过所提供函数实现的测试的所有元素。</pre>
console.log(nonenum_only);</code></pre>
<pre>注:<a href="https://developer.mozilla.orgReference/Global_Objects/Array/filter">Array.filter(filt_func)方法</a>创建一个新数组, 其包含通过所提供函数实现的测试的所有元素。</code></pre>
<h2 id="Notes" name="Notes">提示</h2>
<p>在 ES5 中,如果参数不是一个原始对象类型,将抛出一个 <a href="Reference/Global_Objects/TypeError" title="TypeError类型错误 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a>  异常。在 ES2015 非对象参数被强制转换为对象 <strong></strong></p>
<pre class="brush: js">Object.getOwnPropertyNames('foo');
<pre><code class="language-javascript">Object.getOwnPropertyNames('foo');
// TypeError: "foo" is not an object (ES5 code)
Object.getOwnPropertyNames('foo');
// ['length', '0', '1', '2'] (ES2015 code)
</pre>
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>