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

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

@@ -4,7 +4,7 @@
<p><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/object-create.html" width="100%"></iframe></p>
<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre>Object.create(<var>proto</var>, [<var>propertiesObject</var>])</pre>
<pre>Object.create(<var>proto</var>, [<var>propertiesObject</var>])</code></pre>
<h3 id="Parameters" name="Parameters">参数</h3>
<dl>
<dt><code>proto</code></dt>
@@ -19,7 +19,7 @@
<h2 id="Examples" name="Examples">例子</h2>
<h3 id="用_Object.create实现类式继承">用 <code>Object.create</code>实现类式继承</h3>
<p>下面的例子演示了如何使用<code>Object.create()</code>来实现类式继承。这是一个所有版本JavaScript都支持的单继承。</p>
<pre class="brush: js">// Shape - 父类(superclass)
<pre><code class="language-javascript">// Shape - 父类(superclass)
function Shape() {
this.x = 0;
this.y = 0;
@@ -47,9 +47,9 @@ console.log('Is rect an instance of Rectangle?',
rect instanceof Rectangle); // true
console.log('Is rect an instance of Shape?',
rect instanceof Shape); // true
rect.move(1, 1); // Outputs, 'Shape moved.'</pre>
rect.move(1, 1); // Outputs, 'Shape moved.'</code></pre>
<p>如果你希望能继承到多个对象,则可以使用<span class="short_text" id="result_box" lang="zh-CN"><span>混入的方式。</span></span></p>
<pre class="brush: js">function MyClass() {
<pre><code class="language-javascript">function MyClass() {
SuperClass.call(this);
OtherSuperClass.call(this);
}
@@ -64,10 +64,10 @@ MyClass.prototype.constructor = MyClass;
MyClass.prototype.myMethod = function() {
// do a thing
};
</pre>
</code></pre>
<p><a href="https://developer.mozilla.orgReference/Global_Objects/Object/assign">Object.assign</a> 会把  <code>OtherSuperClass</code>原型上的函数拷贝到 <code>MyClass</code>原型上,使 MyClass 的所有实例都可用 OtherSuperClass 的方法。Object.assign 是在 ES2015 引入的,且可用<a href="Reference/Global_Objects/Object/assign#Polyfill"> polyfilled</a>。要支持旧浏览器的话,可用使用 <a class="external" href="https://api.jquery.com/jQuery.extend/" rel="noopener">jQuery.extend()</a> 或者 <a class="external" href="https://lodash.com/docs/#assign" rel="noopener">_.assign()</a></p>
<h3 id="使用_Object.create_的_propertyObject参数" style="line-height: 18px;">使用 <code>Object.create</code><code>propertyObject</code>参数</h3>
<pre class="brush: js">var o;
<pre><code class="language-javascript">var o;
// 创建一个原型为null的空对象
o = Object.create(null);
@@ -128,7 +128,7 @@ o2 = Object.create({}, {
enumerable: true,
configurable: true
}
});</pre>
});</code></pre>
<h2 id="Polyfill" style="line-height: 24px;">Polyfill</h2>
<p>这个 polyfill 涵盖了主要的应用场景,它创建一个已经选择了原型的新对象,但没有把第二个参数考虑在内。</p>
<p>请注意,尽管在 ES5 中 <code>Object.create</code>支持设置为<code>[[Prototype]]</code><code>null</code>但因为那些ECMAScript5以前版本限制此 polyfill 无法支持该特性。</p>
@@ -147,7 +147,7 @@ o2 = Object.create({}, {
return new F();
};
}</pre>
}</code></pre>
<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>
<table class="standard-table">
<tbody>