Proper inheritance in JavaScript