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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:57:31+00:00 2026-06-15T10:57:31+00:00

var p = function () { this.show = function () { alert(‘hello world!!!’); }

  • 0
var p = function () {
    this.show = function () {
       alert('hello world!!!');
    }
}

p.prototype.show = function() {
    alert('haha');
}

var o  = new p();
o.show();

It alerts "hello world!!!", why?

Can I modify prototype method, if yes how?

  • 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-15T10:57:32+00:00Added an answer on June 15, 2026 at 10:57 am

    That’s because the specific function you define in the constructor overrides the one that is inherited through the prototype.

    From EcmaScript specification :

    Every object created by a constructor has an implicit reference
    (called the object’s prototype) to the value of its constructor’s
    “prototype” property. Furthermore, a prototype may have a non-null
    implicit reference to its prototype, and so on; this is called the
    prototype chain. When a reference is made to a property in an object,
    that reference is to the property of that name in the first object in
    the prototype chain that contains a property of that name. In other
    words, first the object mentioned directly is examined for such a
    property; if that object contains the named property, that is the
    property to which the reference refers; if that object does not
    contain the named property, the prototype for that object is examined
    next; and so on.

    In short : when looking for a function (or any property by its name), you start at the object and then go up in the prototype chain.

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

Sidebar

Related Questions

$.Comment = function() { this.alertme = Alert!; } $.Comment.prototype.send = function() { var self
This code $(#loading).ajaxStart(function() { alert(start); $(this).show(); }); in my mark-up <div style=text-align:center;><img id=loading src=../images/common/loading.gif
I have the following function: this.alphaArray = function() { var alpha = this.alphStr, ,
I have the following snippet of JS var Customer : function() { this.ShipProduct :
This function works as it should, window.setInterval(function(){ var active = $('#frontpageControls a.active'); var next
I have a class: function RustEditor() { this.init = function() { var saveButton =
I am having some trouble wrapping my head around this function: var toStr =
In the js code specified below - var tclass = function(){ this.func2=function(){console.log('func2')}; this.b={ func1:
$(document).ready(function() { $('#username').focus(function() { $(this).val(''); }) $('#username').blur(function() { var l = $(this).val.length; if (l
I find myself doing this repeatedy. $jq(button).filter(function(){ return this.id.match(/^user_(\d+)_edit$/); }).click(function(){ var matches = this.id.match(/^user_(\d+)_edit$/);

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.