1

Hey I am learning JS and trying to write a simple multi-player chess game. I am trying to have all different pieces inherit from the same super class. Like in Java Id have Pawn, Knight, Bishop, etc extend an abstract super class GamePiece. Is that possible?

Or is the closest thing having each type of piece have a separate constructor and reference same functions such as move() or take(), only with different arguments?

4

2 Answers 2

2

Java script is class free object oriented programming language. Javascript follows prototypal inheritance instead of classical inheritance to know more about prototypal inheritance visit this.

About abstract class it will difficult to fit Javascript in to any pure object oriented language. To achieve behavior like abstract class visit this stack-overflow question. You will find various ways for same.

Sign up to request clarification or add additional context in comments.

Comments

1

It is possible to make something akin to an abstract class using prototypes, but that may be more trouble than is necessary in your case.

Since JavaScript is a dynamically typed language, you don't need to have every piece abstracted from a super class, unlike Java. Separate constructors and methods may work well for you.

(If you'd still prefer an abstract class, read through the linked Stack Overflow article, and comment back if you still need help!)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.