Take away from JavaScript – The Good Parts !!

  1. The simple types of JavaScript are numbers, strings, booleans (true and false), null, and undefined. All other values are objects. Numbers, strings, and booleans are object-like in that they have methods, but they are immutable. Objects in JavaScript are mutable keyed collections. In JavaScript, arrays are objects, functions are objects, regular expressions are objects, and, of course, objects are objects.
  2. Objects in JavaScript are class-free.
  3. Objects are passed around by reference. They are never copied.
  4. Every object is linked to a prototype object from which it can inherit properties. All objects created from object literals are linked to Object.prototype, an object that comes standard with JavaScript.
  5. 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.
  6. ‘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.
  7. Objects produced from object literals are linked to Object.prototype & Function objects are linked to Function.prototype, which intern linked to Object.prototype
  8. 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
  9. The function object created by a function literal contains a link to that outer context. This is called closure.
  10. In addition to the declared parameters, every function receives two additional parameters: this and arguments.
  11. There are four patterns of invocation in JavaScript: the method invocation pattern, the function invocation pattern, the constructor invocation pattern, and the apply invocation pattern.
  12. Invocation operator is nothing but a pair of parentheses.
  13. 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.
  14. Function Invocation Pattern: When a function is not the property of an object, then it is invoked as a function
  15. 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.
  16. 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
  17. 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).
  18. A module is a function or object that presents an interface but that hides its state and implementation.
  19. 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.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s