encapsulate javascript code in a function like mw does it