JS: Class overview
Object, parent (prototype), properties
- one of the value type of JavaScript is object.
- objects may have a parent object. we call it its prototype object.
- object has properties.
property lookup goes thru the parent chain.
the above are the most important fundamentals.
Shape of object
- shape of object means the number and type of its property keys and the parent object. shape basically means the “type” of object.
- constructors create objects of the same shape.
Constructor
- constructor is a function that creates object of the same shape.
- constructor is usually called with the
newoperator.
Class
- a class object is a constructor. one way to define a constructor is via the class keyword. (besides other ways to create constructors.)
- when you define a class
class ClassName {body}, thatClassNameis a new constructor.
note: some rare class is constructor that cannot be called, sometimes called abstract class. e.g. JS: Iterator (class).
Instance
instance of a constructor C means a object x that has the same shape as the return value of calling C. usually we say x is created by C, but not necessarily.
Instance property
instance properties are predefined property keys of objects returned by a constructor call. any object created by the constructor call always have these properties.
Subclass
- B is a subclass of A means, the constructor B's parent is the constructor A, and the parent of
B.prototypeisA.prototype.