sample code to implement and recognize common javascript patterns