Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're using a console such a Chrome to log the value of a <code>prototype</code> object then I suggest you don't. The Chrome console, like other browser consoles, formats the output of the prototype object.</p> <p>So for a named function it will log the <code>name</code> of the function, but for an unnamed function it will simply log <code>Object</code>. This does not mean that the <code>prototype</code> of the function points to <code>Object</code> or the function itself. It's just that that's what the console is showing you (someone should sue them for that). See for yourself: <a href="http://jsfiddle.net/2xkpC/" rel="nofollow noreferrer">http://jsfiddle.net/2xkpC/</a></p> <p>How does it know the name of a function from it's <code>prototype</code>? Well, the prototype of a function has a property called <code>constructor</code> which points back to the function itself, and the name of the function is stored as a string in a property called <code>name</code> on the function. So if you log a <code>prototype</code> object then it will display <code>prototype.constructor.name || "Object"</code>:</p> <pre><code>var foo = function(){alert('foo')} console.log(foo.prototype); // logs "Object" function bar(){alert('bar')} console.log(bar.prototype); // logs bar.prototype.constructor.name </code></pre> <p>See the demo here: <a href="http://jsfiddle.net/4bWfn/" rel="nofollow noreferrer">http://jsfiddle.net/4bWfn/</a></p> <p>If you open your console and click that triangle near the logged output then you'll see the <code>constructor</code> and the <code>__proto__</code> properties of the prototype object. Under <code>constructor</code> you'll also see the <code>name</code> property.</p> <p>To know more about inheritance in JavaScript and the <code>prototype</code> object read this answer: <a href="https://stackoverflow.com/a/8096017/783743">https://stackoverflow.com/a/8096017/783743</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.
 

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