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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:10:44+00:00 2026-05-27T15:10:44+00:00

Could someone please explain the significance of prototype.init function in JavaScript and when it

  • 0

Could someone please explain the significance of prototype.init function in JavaScript and when it is called during object instantiation?

Why would you want to overwrite it with an empty function?

I am reading the JavaScript for Web book and am stuck on the this for the past few hours…what is piece of code supposed to achieve?

var Class = function(){ 

var klass = function(){
   this.init.apply(this, arguments); 
};

klass.prototype.init = function(){};

// Shortcut to access prototype 
klass.fn = klass.prototype;

// Shortcut to access class 
klass.fn.parent = klass;

...
}

This is just too much magic for me…:)

  • 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-27T15:10:45+00:00Added an answer on May 27, 2026 at 3:10 pm

    I’m not sure what you don’t understand. init is simply a method like any other, that happens to be called in the constructor and with the same parameters as the constructor. If it’s empty then it’s just because the person who wrote it didn’t need to put anything in it for now but wanted to lay down the groundworks of his class.

    function Foo(a, b, c) {
        this.init.apply(this, arguments); //This simply calls init with the arguments from Foo
    }
    
    Foo.prototype.init = function(a, b, c) {
        console.log(a, b, c);
    }
    
    var f = new Foo(1, 2, 3); //prints 1 2 3
    

    http://jsfiddle.net/Hmgch/

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

Sidebar

Related Questions

Could someone please explain when would I want to use delegation instead of inheritance?
Could someone please explain why Factories are more useful than a simple instantiation during
could someone please explain this to me: I have an MVC method I want
I'm clearly missing something. Could someone please explain why this would happen? #define RANDOM_DEVICE
Could someone please explain function(tx) in the code snippet below, from this page: http://www.webkit.org/demos/sticky-notes/
Could someone please explain to me how the count function works with arrays like
could someone please explain why the following code is throwing an error? // JavaScript
Could someone please explain me why replacing the following $('.post_title a').hover(function () { $(this).parent().parent().parent().parent().find(.post_footer).toggleClass('footer_border')
Could someone please explain the best way to connect to an Interbase 7.1 database
Could someone please explain? I couldn't find anything on the internet, everything talks about

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.