Refactor inheritance in JS