mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-12-16 07:51:52 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -3,13 +3,13 @@
|
||||
<p><strong><code>__noSuchMethod__</code></strong> 属性曾经是指当调用某个对象里不存在的方法时即将被执行的函数,但是现在这个函数已经不可用。</p>
|
||||
<p><code><font face="Open Sans, Arial, sans-serif">在</font><strong>__noSuchMethod__</strong></code> 属性被移除之后,ECMAScript 2015 (ES6) 规范转而采用 <a href="Reference/Global_Objects/Proxy" title="Proxy 对象用于定义基本操作的自定义行为(如属性查找,赋值,枚举,函数调用等)。"><code>Proxy</code></a> 对象, 可以实现下面的效果(以及更多)。</p>
|
||||
<h2 id="语法">语法</h2>
|
||||
<pre class="syntaxbox"><code><var>obj</var>.__noSuchMethod__ = <var>fun</var></code></pre>
|
||||
<pre><code class="language-javascript"><code><var>obj</var>.__noSuchMethod__ = <var>fun</var></code></code></pre>
|
||||
<h3 id="参数">参数</h3>
|
||||
<dl>
|
||||
<dt><code>fun</code></dt>
|
||||
<dd>函数形式如下:</dd>
|
||||
<dd>
|
||||
<pre class="brush: js"><code>function (<var>id</var>, <var>args</var>) { . . . }</code></pre>
|
||||
<pre><code class="language-javascript"><code>function (<var>id</var>, <var>args</var>) { . . . }</code></code></pre>
|
||||
<dl>
|
||||
<dt><code>id</code></dt>
|
||||
<dd>调用的不存在的方法名</dd>
|
||||
@@ -24,7 +24,7 @@
|
||||
<p>If this method cannot be called, either as if <code>undefined</code> by default, if deleted, or if manually set to a non-function, the JavaScript engine will revert to throwing <code>TypeError</code>s.</p>
|
||||
<h2 id="Examples">Examples</h2>
|
||||
<h3 id="Simple_test_of___noSuchMethod__">Simple test of <code>__noSuchMethod__</code></h3>
|
||||
<pre class="brush: js">var o = {
|
||||
<pre><code class="language-javascript">var o = {
|
||||
__noSuchMethod__: function(id, args) {
|
||||
console.log(id, '(' + args.join(', ') + ')');
|
||||
}
|
||||
@@ -38,10 +38,10 @@ o.baz();
|
||||
// foo (1, 2, 3)
|
||||
// bar (4, 5)
|
||||
// baz ()
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="Using___noSuchMethod___to_simulate_multiple_inheritance">Using <code>__noSuchMethod__</code> to simulate multiple inheritance</h3>
|
||||
<p>An example of code that implements a primitive form of multiple inheritance is shown below.</p>
|
||||
<pre class="brush: js">// Doesn't work with multiple inheritance objects as parents
|
||||
<pre><code class="language-javascript">// Doesn't work with multiple inheritance objects as parents
|
||||
function noMethod(name, args) {
|
||||
var parents = this.__parents_;
|
||||
|
||||
@@ -68,9 +68,9 @@ function addParent(obj, parent) {
|
||||
// Add the parent
|
||||
obj.__parents_.push(parent);
|
||||
}
|
||||
</pre>
|
||||
</code></pre>
|
||||
<p>An example of using this idea is shown below.</p>
|
||||
<pre class="brush: js">// Example base class 1
|
||||
<pre><code class="language-javascript">// Example base class 1
|
||||
function NamedThing(name){
|
||||
this.name=name;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ console.log("getAddr is " + (("getAddr" in bob) ? "in" : "not in") + " bob");
|
||||
|
||||
console.log("bob's address is: " + bob.getAddr());
|
||||
// bob's address is: New York
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="Specifications">Specifications</h2>
|
||||
<p>Not part of any specifications. This feature has been removed, see <a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=683218" rel="noopener" title="FIXED: can we remove __noSuchMethod__, use proxies instead?">bug 683218</a>.</p>
|
||||
<h2 id="Browser_compatibility">Browser compatibility</h2>
|
||||
|
||||
Reference in New Issue
Block a user