Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6960103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:21:33+00:00 2026-05-27T15:21:33+00:00

The Original Question I realized I am not 100% sure why this behaves the

  • 0

The Original Question

I realized I am not 100% sure why this behaves the way it does, so I figured it would make a good SO question.

Observe:

Date.bar = function() { return 'called bar'; }
Date.prototype.foo = function() { return 'called foo'; }

Then in your console, note these two lines work:

Date.bar(); // 'called bar'
(new Date).foo() // 'called foo'

But these two blow up and complain about undefined not being a function:

Date.foo();
(new Date).bar();

In theory, shouldn’t adding a method to Date’s prototype make it available when called off Date? What is actually going on here?


What I got out of your answers and from playing around in the console

Basically, Date (that is, window.Date) is not a date object. It’s a function, and it wasn’t constructed from Date.prototype. (Also, date objects do not have the prototype property defined, though of course they still have a prototype chain.) Check it out:

typeof Date; // function
typeof (new Date); // object
Date.prototype.isPrototypeOf(new Date); // true
Date.prototype.isPrototypeOf(Date); // false
(new Date).prototype; // undefined

Realizing that Date is not a date object or the prototype for date objects makes this all make a lot more sense to me. Thanks, everyone.

Also, note that Date.prototype and Date.__proto__ are different! The former is used when Date is run as a function, when creating new date objects. The latter is related to the normal prototype chain (and is Date’s prototype).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:21:34+00:00Added an answer on May 27, 2026 at 3:21 pm

    Adding foo to Date.prototype affects all objects created from invoking Date as a constructor. That’s why foo is visible when you say (new Date()).foo() but not Date.foo()—the latter does not invoke Date as a constructor.

    Remember, when you say new Date() you get an object that’s based on Date’s prototype. You added foo to the prototype, so you’ll get foo on objects created from new Date()

    Adding something directly to Date simply adds it to the Date function. That’s why Date.bar() works, but not (new Date()).bar(). bar is not on the prototype, and therefore not visible to objects created from invoking Date as a constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Original Question: i read that for RESTful websites. it is not good to use
This question is sort of a follow-up to my original question here . Let's
This question relates to my answer of another of my question. The original question
This is a continuation of this question: Original Question (SO) The answer to this
I have a Pygame program that needs text input. The way it does this
EDIT: Upon re-reading my original question I realized very quickly that it was very
This is a follow-up question to a different question I asked not too long
This might seem like a strange question, and perhaps I am not thinking about
After asking this question I realized that to build what I need I'd better
I realize that this question is not unlike asking someone for the name of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.