Improve javascript snippet for immediately invoked function expression