Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>var toClass = {}.toString; </code></pre> <p>is equivalent to</p> <pre><code>var toClass = Object.prototype.toString; </code></pre> <p>because</p> <pre><code>{} </code></pre> <p><em>as an expression</em> (<code>Object</code> initialiser) is equivalent to</p> <pre><code>new Object() </code></pre> <p>where <code>Object</code> is “the standard built-in constructor with that name” (<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.1.5" rel="nofollow">ECMAScript Language Specification, 5.1 Edition, section 11.1.5</a>; and earlier Editions). </p> <p>So <code>{}</code> stands in for a reference to a new <code>Object</code> instance. <code>Object</code> instances by default inherit properties from the object initially referred to by <code>Object.prototype</code> through the prototype chain (<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.5" rel="nofollow">section 15.2.5</a>), including the built-in property <code>Object.prototype.toString</code>. The property value is initially a reference to a <code>Function</code> instance, i.e. the property is a method that you can call (<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.2" rel="nofollow">section 15.2.4.2</a>).</p> <p><code>alert</code> is actually <code>window.alert</code> (and should be written so). <code>window</code> is a property of the ECMAScript global object; the object referred to by that property is a host object in the scope chain which has the <code>alert</code> method. Neither of those is specified in ECMAScript, but they are <a href="https://developer.mozilla.org/en-US/docs/DOM/window.alert" rel="nofollow">provided by some host environments</a> (usually by browsers) as allowed by the Specification (<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-15.1" rel="nofollow">section 15.1</a>).</p> <p>Because it is designed to display alert messages, the <code>alert</code> host method displays the <em>string representation</em> of its first argument. For objects, that includes calling their <code>toString</code> or <code>valueOf</code> method, whichever is supported first (<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-9.8" rel="nofollow">section 9.8</a>). <code>Function</code> instances, such as that referred to by <code>{}.toString</code>, inherit themselves a <code>toString</code> method that returns the implementation-dependent representation of the function (<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.2" rel="nofollow">section 15.3.4.2</a>).</p> <p>There are no classes, though, and the ECMAScript concept of <code>[[Class]]</code> is somewhat different from that of "data type" (see <code>typeof</code> and <code>instanceof</code>). These are languages using <em>prototype-based</em> inheritance (<a href="http://www.ecma-international.org/ecma-262/5.1/#sec-4.2.1" rel="nofollow">section 4.2.1</a>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload