Encapsulating data in JavaScript