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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:39:12+00:00 2026-05-30T02:39:12+00:00

I am testing this at the moment and would like to create a class

  • 0

I am testing this at the moment and would like to create a class B that extends class A but having issues with it at present:

CLASS A

  var CustomClassA = function(){
    console.log('Custom Class A loaded')
    this.message = ' Method Called';

  }

  CustomClassA.prototype    =   {
    constructor : CustomClassA,
    firstMethod : function(msg){
        this._output(msg);
    },
    secondMethod : function(msg){
        this._output(msg);
    },
    thirdMethod: function(msg){
        this._output(msg);
    },
    _output: function(m){
        return console.log(m + this.message);
    }   
  }

CLASS B:

  var CustomClassB =  CustomClassA.extend(

    function CustomClassB(){
        console.log('Custom Class B loaded')
            this.message = ' Method Called from class B';

    },{
        firstMethod : function(msg){this._output(msg);},
            secondMethod : function(msg){this._output(msg);},
        thirdMethod: function(msg){this._output(msg);},
        _output: function(m){return console.log(m + this.message);}
  });

Hoep the two examples makes it easy and hopefully I am doing it right in the first instance.
Thanks

  • 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-30T02:39:13+00:00Added an answer on May 30, 2026 at 2:39 am

    Your first example looks fine.

    The second example would only work if Function.prototype has been given a function property extend, otherwise it will throw a TypeError.

    Try something like this instead.

      function CustomClassB(){
          console.log('Custom Class B loaded');
          this.message = ' Method Called from class B';
      }
    
      CustomClassB.prototype = Object.create(CustomClassA.prototype);
    
      CustomClassB.prototype.firstMethod = function(msg){this._output(msg);};
      CustomClassB.prototype.secondMethod = function(msg){this._output(msg);};
      CustomClassB.prototype.thirdMethod = function(msg){this._output(msg);};
      CustomClassB.prototype._output = function(m){return console.log(m + this.message);};
    

    Or, if you want more syntactic sugar, you can create a convenience function to copy the prototype and merge an object into it, with a calling syntax like the extend you’re using. I wouldn’t necessarily recommend attaching it to Function.prototype though, as there’s a good chance it could collide with some third-party code.


    Older browsers don’t support Object.create. If you need to support legacy browsers, you can write a function like this to emulate it:

    function objectCreate(o) {
        function F() {}
        F.prototype = o;
        return new F();
    }
    

    See here for a look at how this evolved.

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

Sidebar

Related Questions

I'm wondering how to go about testing this. I have a method that takes
I'm testing this out in LINQPad with the CRM plugin. What should my query
I am testing this sample on version 13 of android (3.2) and I have
so i'm testing this so i can use it on my bigger project. I
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
I've written a mapping application which uses GPS. Testing this on my phone (a
IOW, is there a standard way of testing for this, a la: if (!
Will this work for testing whether a value at position index exists or not,
For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
I ran into this issue while testing a rails app deployed to two different

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.