1

I want to clear up a concept. Please tell me if my understand is correct:

Many javascript build-in objects, like Object, String, Array, Date, XMLHttpRequest, we keep saying they are objects, but they are actually constructor functions, am I right?

or these two name are used interchangeably.

Thanks

3
  • 8
    Functions are Objects. ;-) Commented Feb 24, 2015 at 0:51
  • 1
    object doesn't really mean anything. Almost everything is an "object". Now these elements are constructors indeed, which are functions, and contains static methods such as Array.isArray Commented Feb 24, 2015 at 0:54
  • Oh, and XMLHttpRequest is a host object, so a very different animal to the other objects in the OP. Commented Feb 24, 2015 at 0:56

2 Answers 2

2

Ok, to sum it up:

  • every object has a hidden __proto__ property
  • functions are objects that also have a prototype property
  • if, for some object O and function F, O.__proto__ == F.prototype, we say that "O is an instance of F"
  • "F object" is a way to refer to an object that is an instance of "F". For example:

String object: member of the Object type that is an instance of the standard built-in String constructor

and the same for other built-in and user-defined types. If you have

 function Point(x,y) { ... }
 p = new Point(10,20)

then "p is a Point object". In a casual conversation you're also allowed to say "p is a Point" although this isn't strictly correct.

Sign up to request clarification or add additional context in comments.

1 Comment

I guess this is technically true, but I don't think it actually answers the question?
1

Object's prototype is the root prototype for most entities in JavaScript.

The items you list are all constructor functions, yes.

typeof Array // 'function'

Invoking a constructor returns an object.

typeof (new Array()) // 'object'
typeof (new Date()) // 'object'

4 Comments

I believe Object.prototype (which inherits from null) is the root prototype, not the constructor Object itself.
@Derek朕會功夫 you are correct; I think constructors make this much more confusing than it needs to be.
"However, the prototype of Function is Object" nope, Function.prototype is an instance of Function, it is Function.prototype that inherits from Object.prototype (or in your notation, you might write Function.__prototype__ === Function.prototype and Function.prototype.__prototype__===Object.prototype).
@RobG agreed; I've edited to be what I hope is the simplest possible response to OPs question. (OP isn't really asking about prototypes, but there are extensive resources here and elsewhere if and when they do.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.