Update modality.js

1. Moved wrapping code to it's own function, to hep clean up the code and make it more readable.
2. Used a '$' for the local instance in constructor.