JavaScript: wicked closure pattern