Wrap javascript code in a function