Apply your JS skills to key Mozilla projects as an MDN Fellow! http://mzl.la/MDNFellowship

mozilla

Compare Revisions

Object.prototype.__noSuchMethod__

Change Revisions

Revision 72092:

Revision 72092 by Sheppy on

Revision 316389:

Revision 316389 by ethertank on

Title:
__noSuchMethod__
__noSuchMethod__
Slug:
JavaScript/Reference/Global_Objects/Object/noSuchMethod
JavaScript/Reference/Global_Objects/Object/noSuchMethod
Tags:
JavaScript, "JavaScript Reference"
"JavaScript Reference", "JavaScript"
Content:

Revision 72092
Revision 316389
n7    <p>n7    <div>
8      {{ Non-standard_header() }}8      {{ Non-standard_header }}
9    </p>9    </div>
n20            Method of <a href="/en/JavaScript/Reference/Global_Obn20            Method of <a href="/en-US/docs/JavaScript/Reference/G
>jects/Object" title="en/JavaScript/Reference/Global_Objects/Objec>lobal_Objects/Object" title="JavaScript/Reference/Global_Objects/
>t"><code>Object</code></a>>Object"><code>Object</code></a>
n46    <p>n46    <pre class="syntaxbox">
47      <code><em>obj</em>.__noSuchMethod__ = <em>fun</em></code>47<code><em>obj</em>.__noSuchMethod__ = <em>fun</em></code>
48    </p>48</pre>
49    <h2 id="Parameters" name="Parameters">49    <h3 id="Parameters" name="Parameters">
n51    </h2>n51    </h3>
nn60        <pre>
60        <code>function (<em>id</em>, <em>args</em>) { .&nbsp;.&nb61<code>function (<em>id</em>, <em>args</em>) { . . . }</code>
>sp;. }</code> 
62</pre>
n81      By default, an attempt to call a method that doesn't exist n83      By default, an attempt to call a method that doesn't exist 
>on an object results in a <a href="/En/Core_JavaScript_1.5_Refere>on an object results in a <a href="/en-US/docs/JavaScript/Referen
>nce/Global_Objects/TypeError" title="en/Core_JavaScript_1.5_Refer>ce/Global_Objects/TypeError" title="JavaScript/Reference/Global_O
>ence/Global_Objects/TypeError">TypeError</a> being thrown. This b>bjects/TypeError">TypeError</a> being thrown. This behavior can b
>ehavior can be circumvented by defining a function at that object>e circumvented by defining a function at that object's <code>__no
>'s <code>__noSuchMethod__</code> member. The function takes two a>SuchMethod__</code> member. The function takes two arguments, the
>rguments, the first is the name of the method attempted and the s> first is the name of the method attempted and the second is an a
>econd is an array of the arguments that were passed in the method>rray of the arguments that were passed in the method call. The se
> call. The second argument is an actual array (that is, it inheri>cond argument is an actual array (that is, it inherits through th
>ts through the <a href="/en/JavaScript/Reference/Global_Objects/A>e <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Array/
>rray/prototype" title="en/Core_JavaScript_1.5_Reference/Global_Ob>prototype" title="JavaScript/Reference/Global_Objects/Array/proto
>jects/Array/prototype">Array prototype</a> chain) and not the arr>type">Array prototype</a> chain) and not the array-like <a href="
>ay-like <a href="/en/JavaScript/Reference/Functions_and_function_>/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arg
>scope/arguments" title="en/Core_JavaScript_1.5_Reference/Function>uments" title="JavaScript/Reference/Functions/arguments">argument
>s/arguments">arguments object</a>.>s object</a>.
t179</pre>t181</pre><!-- languages({
180    <p>182"fr": "fr/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Objets_globa
 >ux/Object/noSuchMethod"
181      {{ languages( { "fr": "fr/R\u00e9f\u00e9rence_de_JavaScript183}) -->
>_1.5_Core/Objets_globaux/Object/noSuchMethod", "ja": "ja/Core_Jav 
>aScript_1.5_Reference/Global_Objects/Object/noSuchMethod" } ) }} 
182    </p>

Back to History