how to do encapsulation in javascript with example