Please enable JavaScript.
Coggle requires JavaScript to display documents.
Prototypes, inheritance - Coggle Diagram
Prototypes, inheritance
Prototypes
define
objects have a special hidden property [[Prototype]], that is either null or references another object. That object is called “a prototype”
-
prototype chain
It's means, it can go through a lot of intermediaries
-
-
-
The value of “this”
-
No matter where the method is found: in an object or its prototype. In a method call, this is always the object before the dot.
methods are shared, but the object state is not.
for…in loop
-
there’s a built-in method obj.hasOwnProperty(key): it returns true if obj has its own (not inherited) property named key.
-
-
F.prototype
new objects can be created with a constructor function, like new F()
-
-
Default F.prototype, constructor property
-
The default "prototype" is an object with the only property constructor that points back to the function itself.
We can use constructor property to create a new object using the same constructor as the existing one.
-
-
-
-
-
Native prototypes
Object.prototype
When the short notation obj = {} is the same as obj = new Object(). Object is a built-in object constructor function, with its own prototype referencing a huge object with toString and other methods.
-
-
Primitives
-
strings, numbers and booleans
they are not objects. But if we try to access their properties, temporary wrapper objects are created using built-in constructors String, Number and Boolean. They provide the methods and disappear.
-
-
Prototype methods, objects without proto
Object.create(proto, [descriptors])
-
-
truly exact copy of obj
let clone = Object.create( Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj) );