JavaScript function which defines proper types in JavaScript variable or object