javascript: optimize objects