Web Components aims to solve such problems. It consists of three main technologies,which can be used together to create versatile custom elements with encapsulated functionality that can be reused wherever you like without fear of code collisions.
Still stuck?How can we help?