- Objects are passed around by reference. They are never copied.
- Use ‘hasOwnProperty’ instead of ‘typeof’ because hasOwnProperty doesn’t look at prototype chain. In simple words it only returns the properties added to the object.
- ‘For In’ statement can loop over all the properties in the object including the one’s in prototypes. This is similar to Enumeration Order of looping is not guaranteed.
- Objects produced from object literals are linked to Object.prototype & Function objects are linked to Function.prototype, which intern linked to Object.prototype
- Every Function object is created with a prototype property. It’s value is an object with constructor property whose value is a function. This is distinct from the hidden link to Function.prototype
- The function object created by a function literal contains a link to that outer context. This is called closure.
- In addition to the declared parameters, every function receives two additional parameters: this and arguments.
- Invocation operator is nothing but a pair of parentheses.
- Method Invocation Pattern: When a function is stored as a property of an object, we call it a method. When a method is invoked, this is bound to that object. A method can use this to access the object so that it can retrieve values from the object or modify the object.
- Function Invocation Pattern: When a function is not the property of an object, then it is invoked as a function
- Construction Invocation Pattern: If a function is invoked with the new prefix, then a new object will be created with a hidden link to the value of the function’s prototype member, and this will be bound
to that new object.
- Apply Invocation Pattern: The apply method lets us construct an array of arguments to use to invoke a function. It also lets us choose the value of this. The apply method takes two parameters.
The first is the value that should be bound to this. The second is an array of
parameters. This is widely used in AngularJs
- The good news about scope is that inner functions get access to the parameters and variables of the functions they are defined within (with the exception of this and arguments).
- A module is a function or object that presents an interface but that hides its state and implementation.
- Some methods do not have a return value. For example, it is typical for methods that set or change the state of an object to return nothing. If we have those methods return this instead of undefined, we can enable cascades. In a cascade, we can call many methods on the same object in sequence in a single statement.