I can not figure out what a prototype is in javascript, tell me what it is.


in a book with a rhino (David Flanagan) is written

7.4.7. The isPrototypeOf() Method The isPrototypeOf() method returns true if the object to which the method belongs is the prototype of the object passed to the method as an argument. Otherwise, the method returns false . For example:

 var o = {}; Object.prototype.isPrototypeOf(o); // true: o.constructor == Object Object.isPrototypeOf(o); // false o.isPrototypeOf(Object.prototype); // false Function.prototype.isPrototypeOf(Object); // true: Object.constructor == Function 
  • can you expand the question? What kind of prototype does it mean? - Grundy
  • @Grundy updated the question - perfect
  • and in this book, before this chapter, wasn’t there a definition of a prototype? what is it and why? - Grundy
  • @Grundy, the funny thing is that the prototypes are discussed in the 9th chapter. - Nofate
  • 2
    @perfect, don't rush, just read on. - Nofate

2 answers 2

I recommend to familiarize yourself with this material: The object's prototype - the link is a very competent and useful source of knowledge on Javascript.

Excerpt from there:

Objects in JavaScript can be organized into chains so that a property not found in one object is automatically searched in another.

The link is the special property __proto__ .

If one object has a special reference __proto__ to another object, then when reading a property from it, if the property is absent in the object itself, it is searched for in the __proto__ object.

The object pointed to by the __proto__ link is called the “prototype” .

    The prototype is a remote analogue of the class from OOP. In essence, this is an indication to the object from whom the properties and functions it should inherit.

    • This is a very remote analogue of the answer ... - Qwertiy
    • He wrote before the issue was updated - Chad