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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:40:26+00:00 2026-06-13T11:40:26+00:00

function Parent (arg1, arg2) { alert(arg1); this.member1 = arg1; this.member2 = arg2; }; Parent.prototype.update

  • 0
function Parent (arg1, arg2) {

    alert(arg1);

    this.member1 = arg1;
    this.member2 = arg2;
};

Parent.prototype.update = function () {

    // parent method update
};

function Child (arg1, arg2, arg3) {

    Parent.call(this, arg1, arg2);
    this.member3 = arg3;
};

Child.prototype = new Parent;

Child.prototype.update = function () {

    // overwritten method update
};

function init () {

    var childObject = new Child(false, false, false);
    childObject.update();
}

The result are two alerts with

  1. undefined
  2. false

Why does the alert occurs two times? I already searched, but haven’t found anything yet + don’t know what to search for.

The result should be one alert with ‘false’, or am i wrong?

Thx alot!

  • 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-13T11:40:28+00:00Added an answer on June 13, 2026 at 11:40 am

    By using the constructor of Parent to create the prototype for Child, the constructor is being called which is your first alert of undefined.

    In order to create a prototype that still uses the same prototype chain, but doesn’t call the parent constructor as the prototype is created, you need to add another step in between.

    Child.prototype = (function() {
      var Base = function() {};
      Base.prototype = Parent.prototype;
      return new Base();
    }());
    

    This will create an anonymous function (called Base) that has the prototype set to be the prototype of the Parent class, the Child prototype is then assigned to a new Base which will preserve the inheritance, but doesn’t call the constructor of Parent as the prototype chain is created.

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

Sidebar

Related Questions

Question inside the description function Parent(){ this.alertParent(){ alert(Parent alert); } function child(){ // how
I'm looking for something similar to Javascript's arguments array: function parent(){ child.apply(this.arguments); } I'm
So I have a piece of code: jQuery.fn.center = function(parent) { parent = this.parent();
Want to run javascript function from parent window in child window Example I have
I was wondering if there are any difference between function __construct() { parent::__construct(); $this->load->
i have two functions, the parent function is __triggerAction, than child function is __triggerNormal
<?php class Email extends Controller { function Email() { parent::Controller(); $this->load->library('email'); } function index()
Particularly the bit about live.... jQuery('.something').live('click', function() { jQuery(this).parent('form').reset(); }); I suppose this might
I'm trying to do this: $(function() { var parent = window.opener; $(window).bind('unload', function() {
I have this code: $('#label, #btlabel').live('hover',function(){ parent = $(this).parent().attr('id'); position = $(this).parent().position(); positionTop =

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.