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

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><code><strong>hasOwnProperty()</strong></code> 方法会返回一个布尔值,指示对象<strong>自身</strong>属性中是否具有指定的属性</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="syntaxbox"><code><em>obj</em>.hasOwnProperty(<em>prop</em>)</code></pre>
<pre><code class="language-javascript"><code><em>obj</em>.hasOwnProperty(<em>prop</em>)</code></code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>prop</code></dt>
@@ -15,7 +15,7 @@
<h2 id="Examples" name="Examples">示例</h2>
<h3 id="Example:_Using_hasOwnProperty_to_test_for_a_property.27s_existence" name="Example:_Using_hasOwnProperty_to_test_for_a_property.27s_existence">使用 <code>hasOwnProperty</code> 方法判断属性是否存在</h3>
<p>下面的例子检测了对象 <code>o</code> 是否含有自身属性 <code>prop</code></p>
<pre class="brush: js">o = new Object();
<pre><code class="language-javascript">o = new Object();
o.prop = 'exists';
function changeO() {
@@ -25,17 +25,17 @@ function changeO() {
o.hasOwnProperty('prop'); // 返回 true
changeO();
o.hasOwnProperty('prop'); // 返回 false</pre>
o.hasOwnProperty('prop'); // 返回 false</code></pre>
<h3 id="Example:_Direct_versus_inherited_properties" name="Example:_Direct_versus_inherited_properties">自身属性与继承属性</h3>
<p>下面的例子演示了 <code>hasOwnProperty</code> 方法对待自身属性和继承属性的区别:</p>
<pre class="brush: js">o = new Object();
<pre><code class="language-javascript">o = new Object();
o.prop = 'exists';
o.hasOwnProperty('prop'); // 返回 true
o.hasOwnProperty('toString'); // 返回 false
o.hasOwnProperty('hasOwnProperty'); // 返回 false</pre>
o.hasOwnProperty('hasOwnProperty'); // 返回 false</code></pre>
<h3 id="Example:_Itarate_over_properties_not_considering_inherited_properties" name="Example:_Itarate_over_properties_not_considering_inherited_properties">遍历一个对象的所有自身属性</h3>
<p>下面的例子演示了如何在遍历一个对象的所有属性时忽略掉继承属性,注意这里 <a href="Reference/Statements/for...in" title="for...in语句以任意顺序遍历一个对象的可枚举属性。对于每个不同的属性语句都会被执行。"><code>for...in</code></a>  循环只会遍历可枚举属性,所以不应该基于这个循环中没有不可枚举的属性而得出 <code>hasOwnProperty 是严格限制于可枚举项目的(如同 </code><a href="Reference/Global_Objects/Object/getOwnPropertyNames" title="Object.getOwnPropertyNames()方法返回一个由指定对象的所有自身属性的属性名包括不可枚举属性但不包括Symbol值作为名称的属性组成的数组。"><code>Object.getOwnPropertyNames()</code></a>)。</p>
<pre class="brush: js">var buz = {
<pre><code class="language-javascript">var buz = {
fog: 'stack'
};
@@ -46,10 +46,10 @@ for (var name in buz) {
else {
alert(name); // toString or something else
}
}</pre>
}</code></pre>
<h3 id="使用_hasOwnProperty_作为属性名"><code>使用 hasOwnProperty</code> 作为属性名</h3>
<p>JavaScript 并没有保护 hasOwnProperty 属性名,因此某个对象是有可能存在使用这个属性名的属性,使用<strong>外部</strong>的 <code>hasOwnProperty 获得正确的结果是需要的:</code></p>
<pre class="brush: js">var foo = {
<pre><code class="language-javascript">var foo = {
hasOwnProperty: function() {
return false;
},
@@ -62,7 +62,7 @@ foo.hasOwnProperty('bar'); // 始终返回 false
({}).hasOwnProperty.call(foo, 'bar'); // true
// 也可以使用 Object 原型上的 hasOwnProperty 属性
Object.prototype.hasOwnProperty.call(foo, 'bar'); // true</pre>
Object.prototype.hasOwnProperty.call(foo, 'bar'); // true</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>