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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:10:09+00:00 2026-05-25T01:10:09+00:00

if i have: function Base (){ this.sayHi = function(){ alert(‘hi’); } } function Thing

  • 0

if i have:

function Base (){
    this.sayHi = function(){
        alert('hi');
    }
}

function Thing (val){
    this.value = val;
}

var bob = new Thing("bob");

Is there some way I can now say that bob inherits from Base so that I could call:

bob.sayHi();

Basically have all the methods and properties of the Base class available on that instance?

A more relevant example with solution based on CMS’s post:

Here Items could represent data returned by the server..

var Items = [
    { sku: 123, type:'buggy', title:'This is a title', description: 'this is a description' },
    { sku: 234, type: 'baby-monitor', title: 'This is a title 2', description: 'this is a description 2' }
]

function ItemMethods() {
    this.BannerHTML = function () {
        return '<div class="banner _item_' + this.type + '_' + this.sku + '"><h2>' +
            this.title + '</h2><p>' +
            this.description + '</p></div>';
    };
}

Items.GetBySKU = function (code) {
    for (var i = 0; i < Items.length; i++) {
        if (Items[i].sku == code) {
            return Items[i];
        }
    }
};

$.each(Items, function (i, item) {
    ItemMethods.apply(item);
});

alert(Items.GetBySKU(234).BannerHTML());

Any further comments or solutions gladly accepted.. always interested in potential solutions to a problem 😉

  • 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-25T01:10:11+00:00Added an answer on May 25, 2026 at 1:10 am

    Note that the properties that you create within the constructor, have nothing to do with the constructor’s prototype, they are own properties of the object you create using new Base();, they are not inherited. However, I think what you want to do it to apply the Base constructor function on the newly created object of Thing:

    function Base (){
        this.sayHi = function(){
            alert('hi');
        }
    }
    
    function Thing (val){
        Base.apply(this, arguments);
        this.value = val;
    }
    
    var bob = new Thing("bob");
    bob.sayHi();
    

    Note that bob will not inherit from Base (it won’t have access to properties added to Base.prototype)

    bob instanceof Base;  // false
    bob instanceof Thing; // true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have some code like this in AS3 for(...) thing = new
I have a base class with an optional virtual function class Base { virtual
I have a base class Foo that has an Update() function, which I want
I have a function that gets x(a value) and xs(a list) and removes all
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
I have a function pointer defined by: typedef void (*EventFunction)(int nEvent); Is there a
I have one header file which uses a virtual function. This is declared and
I have seen this question http://www.careercup.com/question?id=384062 class Base { public : virtual void method
I have a class Base in base.h , which has a template function class
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035

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.