Learning Javascript : Object Creation Patterns

There are majorly Four patterns to create an Object in Javascript.

  • Constructor Pattern.
  • Factory Pattern
  • Prototype Pattern
  • Dynamic Prototype Pattern.
  • Use this keyword to attach
  • Don’t return anything.
Factory Pattern – http://jsbin.com/rejaca/edit?js,console
  • Create Dummy Object
  • Return this object after 
Prototype Pattern
  • Put things in Shared space (Prototype).
  • Kind of assign default values.
Dynamic Prototype Pattern. – http://jsbin.com/tajiwof/edit?js,console
// Dynamic Prototype Pattern  – Object Creation

Lexical Scoping 
Inner Function Automatically has the Outside variables access.
// Lexical Scoping  – Inner Functions have access to OUTER Variables
Closure in Javascript

290 total views, 4 views today

 

Leave a Reply

Your email address will not be published. Required fields are marked *