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

  • SEARCH
  • Home
  • 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 8489257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:46:45+00:00 2026-06-10T21:46:45+00:00

For a while now I have been developing javascript applications, usually smaller scripts to

  • 0

For a while now I have been developing javascript applications, usually smaller scripts to accomplish simple tasks but also a fairly large and complex application using Dean Edwards’ base2 library for creating pseudo classic OO classes with inheritance,… in javascript.

The base2 library served me pretty well, mainly because it enabled me to follow the classic OO paradigm, which I am quite familiar with. I also know of several other frameworks that can be used to build more robust and mature javascript applications (backbone.js for example). But I always have the feeling that this type of library is a way of ‘cheating’, to construct a way to write code using principles the language actually isn’t suited for.

I have been reading up on different ways to define objects/functions, instantiate them and achieving polymorphism using prototypal inheritance. This is really how the language works at a fundamental level and I feel like I should take advantage of that rather than deciding it is annoying or strange and trying to find a way to do things the way I’m used to (the classical OO way).

So, looking at applications that are not using this type of library, there seem to be so many ways to write your application while for traditional general purpose languages like Java, C++, … the right way of building your applications seems more clearly defined (it’s a lot easier to distinguish good from bad code). If somebody would ask me tomorrow: “start developing projectX for me”, I would have no idea how to start defining and structuring my objects in a way I can be sure won’t come back to bite me later when it’s too late to restructure the whole thing.

What would a professional complex js app skeleton look like, using prototypal inheritance, so without using any type of library for mimicking classic OO, assuming a simple MVC type of app but easily scalable to more complex proportions. How to define my objects? How to keep objects/’classes’ grouped together (namespacing)? In other words: how to do it without ending up with a mess nobody understands anymore?

  • 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-06-10T21:46:47+00:00Added an answer on June 10, 2026 at 9:46 pm

    There are two patterns I follow in creating object oriented Javascript ‘classes’ (thought there are no real classes in JS, we can mimic them). First is more familier OO way and simple to understand.

    // in JS, functions can be used as OO classes
    var Person = function(name) {
        var self = this;
    
        //private methods and attributes
        this.getNickname = function(){
            return "Yaka";
        };
    
        //public methods and attributes (return obj)
        return {
            getName : function() {
                return name + ' ' + self.getNickname();
            }
        }
    };
    
    //static functions attached to 'Person' class 
    Person.hasBrain = function() {
        return true;
    }
    

    This model lets you to have private, public and static sections for your classes allowing good encapsulation. But this not the optimal way as every object will carry it’s own copy of all instance methods. You can avoid having multiple copies of the instance methods with prototype based programming:

    // in JS, functions can be used as OO classes
    var Person = function(name) {
        this.name = null;
    };
    
    // use of prototypes improves performance and memory use
    Person.prototype.getName = function() {
        return this.name;
    }
    
    Person.prototype.setName = function(name) {
        this.name = name;
    }   
    

    This doesn’t look very familier for traditional OO programmers, but the optimum way for using javascript resources. It goes well with inheritance too.

    var Manager = function() {}
    Manager.prototype = new Person();
    

    In practice I use the prototypical approach for base/framework classes that are being used heavily in the application. For classes being used occasionally or for few instances, I use the approach discussed before.

    I also recommend you to use an AMD library such as requirejs, and define a single class per physical file. Then use an build optimizer to optimize your files in to a single script.

    I copied above 2 approaches from the unit tests in BoilerplateJS reference architecture. Have a look at the code in BoilerplateJS, it will give you more ideas on how to approach complex application development with JS.

    Disclaimer: I’m the main author of BoilerplateJS

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

Sidebar

Related Questions

I have been developing flex applications for a while now and at last i
I've been developing Web applications for a while now and have dipped my toe
I have been using PHPUnit for a while now, but suddenly hit a big
I have been using the CodeIgniter system for a while now - but it
I have been developing web apps for a while now and for the past
A sselenium program I have been developing for a while now comes up with
I've been developing in PHP for a while now, and I still have not
I've been developing Rails for a while, but somehow avoiding using capistrano until now.
I have been developing wordpress plugins for a while now and i always seem
I have been developing server side applications in java, and now I have been

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.