Implementing oop in javascript with a better way