Attempting to implement something like polymorphism in JavaScript...