Good Parts • Lambda • Dynamic objects • Loose typing • Object literals
Bad Parts • Global Variables • + adds and concatenates • Semicolon inser3on • typeof • with and eval • == and != • false, null, undeﬁned, NaN
Minimizing global variables /*#Title:#Minimizing#Globals#Description:#they#are#declared#outside#of#function#or#simply#used#without#being#declared!*/!myglobal!=!"hello";!//#antipattern!console.log(myglobal);!//#"hello"!console.log(window.myglobal);!//#"hello"!console.log(window["myglobal"]);!//#"hello"!console.log(this.myglobal);!//#"hello"!
CREATIONAL Builder constructs complex objects by separa3ng construc3on and representa3on Factory Method creates objects without specifying the exact class to create Singleton restricts object crea3on for a class to only one instance STRUCTURAL Decorator dynamically adds/overrides behavior in an exis3ng method of an object Facade provides a simpliﬁed interface to a large body of code BEHAVIORAL Chain of responsibility delegates commands to a chain of processing objects Command creates objects which encapsulate ac3ons and parameters Mediator allows loose coupling between classes by being the only class that has detailed knowledge of their methods Observer is a publish/subscribe paSern which allows a number of observer objects to see an event