Reputation: 413
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
Upvotes: 1
Views: 168
Reputation: 36592
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'
Upvotes: 1
Reputation: 214969
Ok, to sum it up:
__proto__
propertyprototype
propertyO.__proto__ == F.prototype
, we say that "O is an instance of F"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.
Upvotes: 2