Prototype Flashcards
What kind of property does every JS object have?
Prototype property
What are the two ways prototype is being used for?
Inheritance & accessing properties on (different) objects
What is prototype property?
It is a built-in mechanism which every JS object has by which objects can inherit different methods and properties from one another
What does prototype attribute do?
Property attribute specifies the object from which it inherits properties
What is inheritance in programming? In JS, what do you use for that?
Inheritance is a system where objects can inherit properties and methods from other objects. In JS you use prototype for that
What’s the alias for prototype attribute?
Prototype object
If you want to access the property of an object, where does the search start and how does it go? At what point will the search end? How is it called?
It starts from the object itself, if the property ain’t there, it goes to the “parent” of that object (which is the object’s prototype), if it’s not there it’ll go to its prototype etcetc. The search continues until there aren’t anymore prototypes to go to.
It is called the prototype chain.
What can be used so that one object can inherit prototypes from another?
Object.create()
Why Obj1.prototype = Obj2.prototype is a bad idea?
Because now the Obj2 has been overwritten. We want to base Obj1 on Obj2 and not overwrite it