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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:18:36+00:00 2026-05-20T08:18:36+00:00

I am building an application in JavaScript using ExtJS. As I add more functionality

  • 0

I am building an application in JavaScript using ExtJS.

As I add more functionality to it, I find that I would like to encapsulate functionality into classes which inherit from each other. Coming from C# and PHP, I find the object-oriented paradigms in JavaScript quite different and don’t really see that it offers what I need to do this.

Therefore, I am working through the DailyJS Let’s Build a Framework tutorial which seems to be a very structured way to turn JavaScript into more of an object-oriented language with classes, inheritance, etc. From my point of view, this is what I need, yet I feel odd having to build all this base functionality by myself on top of JavaScript just to be able to use the language as I would PHP or C#, i.e. build a class hierarchy and then instantiate objects with it.

For my task at hand (reducing complexity through abstraction) is building an OOP-framework like this on top of Javascript the right approach, or should I be using JavaScript in another way, or perhaps using a framework that already exists?

Below are some examples of how this framework builds and inherits classes.

HTML:

<!DOCTYPE html>
<html>
    <body>
    <meta http-equiv="Content-Type" content="text/html; charset: utf-8">
    <script type="text/javascript" src="js/dp.core.js"></script>
    <script type="text/javascript" src="js/dp.oo.js"></script>
    <script type="text/javascript">


        //core
        document.write('<p>' + dp.VERSION + '</p>');

        //define and use class
        var Layout = dp.Class({
            initialize: function(idCode, name) {
                this.idCode = idCode;
                this.name = name;
            },
            showChildren: function() {
                return '(show children)';
            },
            toString: function() {
                return 'idCode=' + this.idCode + ', name=' + this.name;
            }
        });
        var layout = new Layout('layout', 'Layout');
        document.write('<p>' + layout.showChildren() + '</p>');
        document.write('<p>' + layout + '</p>');

        //define and use inheriting class
        var OrderApprovalLayout = dp.Class(Layout, {
            initialize: function() {
                this.$super('initialize', arguments);
            },
            toString: function() {
                return 'OrderApprovalLayout: ' + this.$super('toString');
            }
        });
        var orderApprovalLayout = new OrderApprovalLayout('orderApprovalLayout', 'Order Approval Layout');
        document.write('<p>' + orderApprovalLayout + '</p>');

    </script>
</body>
</html>

JavaScript:

dp.Class = function() {
  return dp.oo.create.apply(this, arguments);
}

dp.oo = {
  create: function() {
    var methods = null,
        parent  = undefined,
        klass   = function() {
          this.$super = function(method, args) { return dp.oo.$super(this.$parent, this, method, args); };
          this.initialize.apply(this, arguments);
        };

    if (typeof arguments[0] === 'function') {
      parent = arguments[0];
      methods = arguments[1];
    } else {
      methods = arguments[0];
    }

    if (typeof parent !== 'undefined') {
      dp.oo.extend(klass.prototype, parent.prototype);
      klass.prototype.$parent = parent.prototype;
    }

    dp.oo.mixin(klass, methods);
    dp.oo.extend(klass.prototype, methods);
    klass.prototype.constructor = klass;

    if (!klass.prototype.initialize)
      klass.prototype.initialize = function(){};

    return klass;
  },

  mixin: function(klass, methods) {
    if (typeof methods.include !== 'undefined') {
      if (typeof methods.include === 'function') {
        dp.oo.extend(klass.prototype, methods.include.prototype);
      } else {
        for (var i = 0; i < methods.include.length; i++) {
          dp.oo.extend(klass.prototype, methods.include[i].prototype);
        }
      }
    }
  },

  extend: function(destination, source) {
    for (var property in source)
      destination[property] = source[property];
    return destination;
  },

  $super: function(parentClass, instance, method, args) {
    return parentClass[method].apply(instance, args);
  }
};
  • 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-20T08:18:36+00:00Added an answer on May 20, 2026 at 8:18 am

    I would advice an alternative of Object composition and using a more functional approach to your JavaScript.

    Stick to Object constructors only.

    For example

    function Layout(pr_id, pr_name) {
        var name = pr_name;
        var id = pr_id;
    
        this.showChildren = function() {
             return "(showChildren)";
        };
    
        this.toString = function() {
             return "name : " + name + " id : " + id;
        };
    }
    
    function OrderApprovalLayout(id, name) {
        var layout = new Layout(id, name);
        // bind the `this` reference inside `layout` to `layout`
        _.bindAll(layout);
        // extend `this` with all the `layout` methods
        _.extend(this, layout);
        // overwrite `Layout.toString`
        this.toString = function() {
            return "OrderApprovalLayout: " + layout.toString();
        };
    }
    

    This relies on underscore and _.bindAll and _.extend

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

Sidebar

Related Questions

I'm building a multi-threaded client side javascript application, and I would like to have
I'm building a simple email functionality in my web application and would like to
I am building an application where most of the HTML is built using javascript.
I'm currently building a small web application that includes a fair amount of JavaScript.
I am building a web application that uses a lot of Javascript. Now I
I am building application that required some data from iPhone's Call log(read only). The
When building an application, is there any meaningful difference between the idea of Find
I'm building an application that is targeting Windows, Mac and Linux soon. I was
I'm building an application in C# using WPF. How can I bind to some
We're currently building an application that executes a number of external tools. We often

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.