Javascript: patterns