-
An object
Is a hard shell that hides the gooey complexity inside it and instead offers us a few knobs and connectors (such as methods) that present an interface
-
Encapsulation
- The idea that the data of an object should not be directly exposed. Instead, callers that want to achieve a given result are coaxed into
- proper usage by invoking methods rather than accessing the data directly.
-
Methods
- Are simply properties that hold functions.
- var rabbit = {};
- rabbit.speak = function(line) {
- console.log("The rabbit says" + line + "'");
- };
-
method call()
A different this object can be assigned when calling an existing function. this refers to the current object, the calling object. Accepts an argument list.
-
prototype
A prototype is another object that is used as a fallback source of properties
-
Constructors
In JavaScript, calling a function with the new keyword in front of it causes it to be treated as a constructor. A more convenient way to create objects that derive from some shared prototype is to use a constructor. Constructors should be capitalize
-
new
An object created with the new is said to be an instance of its constructor
-
prototype interference
A prototype can be used at any time to add new properties and methods to all objects based on it.
-
enumerable properties
All properties that we create by simply assigning to them are enumberable
-
hasOwnProperty method
This method tells us whether the object itself has the property, without looking at its prototypes. This is often a more useful piece of information than what the in operator gives us.
-
non enumerable properties
The standard properties in Object.prototype are all non enumerable. It is possible to define our own nonenumerable properties by using Object.defineProperty function, which allows us to control the type of property we are creating.
-
Prototype-less Objects
We can use Object.create function to create an object with a specific prototype. We are allowed to pass null as the prototype to create a fresh object with no prototype.
-
Polymorphism
When a piece of code is written to work with objects that have a certain interface - in this case, a toString method - any kind of object that happens to support this interface can be plugged into the code, and it will just work. Polymorphic code can work with values of different shapes, as long as they support the interface it expects.
-
Getters and Setters
We can specify properties that, from the outside, look like normal properties but secretly have methods associated with them. In object literal, the get and set notation allows you to specify a function to be run when the property is read or written.
-
Object.defineProperty can be used to add a getter
- Object.defineProperty(Textcell.prototype, "heightProp", { get: function() { return this.text.length; } });
- When a getter but not setter is defined, writing to the property is simply ignored.
-
Inheritance
It allows us to build slightly different data types from existing data types with relatively little work. Typically, the new constructor will call the old constructor (using the call method in order to be able to give it the new object as its this value)
-
The instanceOf operator
It is occasionally useful to know whether an object was derived from a specific constructor. Binary operator - the operator will see through inherited types.
|
|