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 7638335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:09:05+00:00 2026-05-31T08:09:05+00:00

I guess probably the most used technique to mimic classes and class-inheritance in Javascript,

  • 0

I guess probably the most used technique to mimic classes and class-inheritance in Javascript, which is outside of the BIG frameworks is the Simple Javascript Inheritance solution from John Resig (http://ejohn.org/blog/simple-javascript-inheritance).
At least in the jquery ecosystem. Some people also have extracted the inheritance solution of backbone.js (which seems to be based on goog.inherits http://bolinfest.com/javascript/inheritance.php).

I like both solutions. But somehow I feel that there are simpler solutions, especially in some subareas, for instance Javascript singletons, that take into account the fact that JS has only objects.

Two books/blogs have impressed me a lot in this respect. The first was “Javascript Patterns” from Stoyan Stefanov (chapter “code reuse patterns”), especially “inheritance”/code reuse through an “extend” function (shallow copy).

The other was “AMD Module Patterns: Singleton” (http://unscriptable.com/2011/09/22/amd-module-patterns-singleton). This was quite fascinating:

Since AMD only executes the definition function once, we’ve essentially created a singleton.

So I want to have such AMD singletons, simply an object which is returned by the amd factory function/definiton function.

But I also want to have the possibility to “inherit”/reuse methods from other AMD singletons. This would be achievable with an extend function.

Now comes the question:
Extend just gives me the “public” methodes of AMD singleton modules, but I also want to have the “private ones” (closure scope functions).

I could inject a “extractAllMethods” method into singleton modules that return all (also private) their methods to the method caller and combine it with an extend to merge it into the new singleton, but is this a good solution?

Does anybody have a better solution to extract also the private methods out of an AMD singleton module?

Thanks in advance
Wolfgang

  • 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-31T08:09:07+00:00Added an answer on May 31, 2026 at 8:09 am

    I found the solution by myself!

    I found a blog from the well respected Nicholas C. Zakas

    His solution for me is:
    I do not need private methods through closures.
    Closures make the code a lot of harder to maintain.
    So, with no private methods, I will just need extend or the prototype property.

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

Sidebar

Related Questions

This is probably an easy one, but I'm missing something I guess. The problem
My guess is that class variables (class var) are truly global in storage (that
I guess this is an odd one, and the answer is most likely it
I guess it should be a common technique, However, I tried the following two
I guess most people understand that the complexity of size() function is not guaranteed
I think I can probably guess that the answer to this question is going
Guess that I have a TextView that I want to update it in some
I guess the real question is: If I don't care about dirty reads, will
I guess I'll illustrate with an example: In this game you are able to
I guess I'm really after an aid to help people who forget, Cruise Control

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.