Try taking a look into either prototypes or closures.
From MDN (prototypes):
All objects in JavaScript are descended from Object; all objects
inherit methods and properties from Object.prototype Object.prototype,
although they may be overridden (except an Object with a null
prototype, i.e. Object.create(null)). For example, other constructors'
prototypes override the constructor property and provide their own
toString methods. Changes to the Object prototype object are
propagated to all objects unless the properties and methods subject to
those changes are overridden further along the prototype chain.
Many agree that changing the Object
type directly can cause issues, especially when linking in other libraries. Becasue of this, it's usually best to use closures.
From MDN (closures):
Languages such as Java provide the ability to declare methods private,
meaning that they can only be called by other methods in the same
class.
JavaScript does not provide a native way of doing this, but it is
possible to emulate private methods using closures. Private methods
aren't just useful for restricting access to code: they also provide a
powerful way of managing your global namespace, keeping non-essential
methods from cluttering up the public interface to your code.