Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:14+00:00 2026-05-25T14:23:14+00:00

// A convenient function that can be used for any abstract method function abstractmethod()

  • 0
// A convenient function that can be used for any abstract method
function abstractmethod() { throw new Error("abstract method"); }

// The AbstractSet class defines a single abstract method, contains().
function AbstractSet() { throw new Error("Can't instantiate abstract classes");}
AbstractSet.prototype.contains = abstractmethod;

From “Javascript: The Definitive Guide – 9.7.4 Class Hierarchies and Abstract Classes”
I understand the utility of abstract classes in JavaScript. What I don’t understand is the necessity or use of setting abstract methods that only throw an error. You can’t create an instance of that class, so only instances of the subclasses will exist. They’ll each have their own definition for these methods, so why establish an inheritance to a method that just throws a generic error?

Thank you in advance for your guiding response.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:23:15+00:00Added an answer on May 25, 2026 at 2:23 pm

    I assume that the purpose of this is that it’s not a generic error – it’s an error that informs you where you went wrong (i.e. you failed to override the method in a subclass). If you didn’t define that method, you would get an error saying “Undefined is not a function” (or something similar) and you’d have to spend time hunting around your code to understand why – this way it fails in a more verbose and useful manner.

    The other reason, I’d assume, is to indicate the class interface to downstream developers implementing subclasses. Javascript doesn’t have any kind of formal interface declaration, so it’s helpful to be able to inspect the abstract class and see what methods I’m expected to implement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Jar is a convenient way to use java, as every class can be included
I'm writing a class library that provides convenient object-oriented frontends to the C API
The function CreateFileMapping can be used to allocate space in the pagefile (if the
I had a calculator app that can draw a function. I'm stuck in an
I'm trying to implement a C# method that can log a message with a
I am working on a function that will be used by no less than
In SQLSERVER 2005, I'm using table-valued function as a convenient way to perform arbitrary
Java has a convenient split method: String str = The quick brown fox; String[]
I'm no stranger to __get(), and have used it to make some very convenient
How can I make the code below into a function? # split the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.