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 5957925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:28:12+00:00 2026-05-22T18:28:12+00:00

I have a simple class in javascript: function foo() { this.bar = bar; }

  • 0

I have a simple class in javascript:

function foo() {
    this.bar = "bar";
}

var test = new foo;

console.log(foo.prototype,foo.__proto__)
/*output: foo {
               constructor: function foo() { 
               __proto__:   Object
              }
          ,
          function Empty() {}
*/
console.log(test,test.prototype,test.__proto__,test.__proto__.__proto__)
/*output: foo {
              bar: "bar"
              __proto__: foo
          }
          ,
          undefined
          ,
          foo {
              constructor: function foo() {
              __proto__: Object
          }
          ,
          Object {
              ...
          }
      */

What i dont understand:

At the first log the foo.prototype had the __proto__ attribute which was an Object
At the second log the test.__proto__ had the __proto__ attribute which was an Object

When to use __proto__ and when prototype, what is the difference?


UPDATE:

In John Resig’s blog in the instanceOf section there is something waht I don’t understand:

If i use var asd = "asd";Object.getPrototypeOf(asd) it throws a TypeError but
If i use var dsa = new String("dsa");Object.getPrototypeOf(dsa) it returns String
But asd.constructor.prototype == dsa.constructor.prototype is true

Why is the Object.getPrototypeOf(asd) throws error? This is a string, isn’t it?

  • 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-22T18:28:13+00:00Added an answer on May 22, 2026 at 6:28 pm

    Always use prototype or Object.getPrototypeOf.

    __proto__ is non-standard and has been deprecated by Mozilla.

    John Resig has a good blog entry about it.


    The reason why test.prototype is undefined is because you created a new object that does not have a constructor prototype. Here’s an example of when to use Object.getPrototypeOf.

    js> function foo(){}
    js> typeof foo.prototype;
    object
    js> var f = new foo();
    js> typeof f.prototype;
    undefined
    js> typeof Object.isPrototypeOf(f);
    object
    js> typeof f.constructor.prototype;
    object
    js> foo.prototype === Object.getPrototypeOf(f);
    true
    js> foo.prototype === f.constructor.prototype;
    true
    

    As you can tell, inheritance in JavaScript is tricky. Lets look at an example:

    js> typeof "asdf";
    string
    js> typeof String("asdf");
    string
    

    The string literal is of type string. The same is true when calling String() as a function. Now, because of behavior of the new operator, a new object is created, with the prototype of String() as its parent.

    js> var s = new String("asdf");
    js> typeof s;
    object
    

    Because JS likes to coerce things, you can get at the string literal a few ways:

    js> s
    asdf
    js> s.valueOf();
    asdf
    js> typeof s
    object
    js> typeof s.valueOf();
    string
    

    Prototypal Inheritance in JavaScript by Crockford helped me a lot when learning about JS inheritance.

    From Mozilla’s Strings page:

    String objects may be created by
    calling the constructor new String().
    The String object wraps JavaScript’s
    string primitive data type with the
    methods described below. The global
    function String() can also be called
    without new in front to create a
    primitive string. String literals in
    JavaScript are primitive strings.

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

Sidebar

Related Questions

I want to define a JavaScript class, Foo. Foo = function(value){ this.value = value;
I have a simple javascript class. One method of this class sets up a
I made a simple javascript class like this: function Horse() { this.color = 'brown';
I have the simple class using auto-implemented properies: Public Class foo { public foo()
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
I have a very simple javascript class that does an ajax call to a
Ok, I have a simple javascript function in a bookmarklet that finds all of
I have a simple class that essentially just holds some values. I have overridden
For example I have a simple class like public class Person{ public int Age
I have a really simple class with two methods; One that will be called

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.