The answer to this question:
What is the initial value of a JavaScript function's prototype property?
has this sentence:
The initial value of prototype on any newly-created Function instance is a new instance of Object
As far as I know, Javascript doesn’t have classes and the word ‘instance’ therefor doesn’t make sense in my head. How should one interpret ‘instance’ in Javascript?
Sorry, I don’t have enough rep to put my question in the comment thread on that answer.
You’re right that JavaScript doesn’t have classes (yet), but it does have constructor functions, an
instanceofoperator that defines a relationship between objects and constructors, and a form of inheritance based on prototype chains.obj instanceof ctoris true whenctor.prototypeis onobj‘s prototype chain.Modulo the caveat below, you could implement
instanceofin EcmaScript 5 thusUnless you go around reassigning prototypes (
o = new MyConstructor(); MyConstructor.prototype = somethingElse) it should be the case thatnew MyConstructor() instanceof MyConstructor.Section 15.3.5.3 explains this in detail.
This isn’t the whole story because host objects (like DOM nodes) are allowed to implement the
[[HasInstance]]internal method however they like but most browsers implement host objects to behave as closely to native objects as possible.