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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:07:51+00:00 2026-06-06T03:07:51+00:00

In this snippet of Google Closure javascript code involving a constructor, why is goog.base(this);

  • 0

In this snippet of Google Closure javascript code involving a constructor, why is goog.base(this); necessary? Doesn’t Foo already inherit from Disposable with goog.inherits(foo, goog.Disposable);?

goog.provide('Foo');

/**
 * @constructor
 * @extends {goog.Disposable}
 */
Foo = function() {
  goog.base(this);
}     
goog.inherits(foo, goog.Disposable);

foo.prototype.doSomething = function(){
  ...
}

foo.prototype.disposeInternal = function(){
  ...
}
  • 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-06T03:07:52+00:00Added an answer on June 6, 2026 at 3:07 am

    goog.inherits(childConstructor, parentConstructor)

    goog.inherits() establishes the prototype chain from the child constructor
    to the parent constructor.

    /**
     * Inherit the prototype methods from one constructor into another.
     * @param {Function} childCtor Child class.
     * @param {Function} parentCtor Parent class.
     */
    goog.inherits = function(childCtor, parentCtor) {
      /** @constructor */
      function tempCtor() {};
      tempCtor.prototype = parentCtor.prototype;
      childCtor.superClass_ = parentCtor.prototype;
      childCtor.prototype = new tempCtor();
      /** @override */
      childCtor.prototype.constructor = childCtor;
    };
    

    In addition to prototype properties, constructors may have “own” properties
    (i.e. instance-specific properties added to this). Since goog.inherits()
    does not call the parent constructor, own properties are not copied to the
    child constructor and any initialization code in the parent does not get
    executed. For these reasons, the standard pattern is to chain constructors as in the following example.

    /**
     * @param {string} name The parent's name.
     * @constructor
     */
    var Parent = function(name) {
      /**
       * @type {string}
       * @private
       */
      this.name_ = name;
    }
    
    /**
     * @param {string} name The child's name.
     * @constructor
     * @extends {Parent}
     */
    var Child = function(name) {
      Parent.call(this, name);
    }
    goog.inherits(Child, Parent);
    

    goog.base(self, opt_methodName, var_args)

    goog.base() is a helper function for calling parent methods so that you do
    not need to explicitly use call() or apply().

    If [goog.base()] is called from a constructor, then this calls the
    superclass contructor with arguments 1-N.

    If this is called from a prototype method, then you must pass the name of
    the method as the second argument to this function. If you do not,
    you will get a runtime error. This calls the superclass’ method with
    arguments 2-N.

    This function only works if you use goog.inherits to express inheritance
    relationships between your classes.

    In Closure code it is common to chain constructors with goog.base() rather
    than calling the parent constructor explicitly.

    /**
     * @param {string} name The child's name.
     * @constructor
     * @extends {Parent}
     */
    var Child = function(name) {
      goog.base(this, name);
    }
    goog.inherits(Child, Parent);
    

    Further Reading

    • Inheritance Patterns in JavaScript by Michael Bolin
    • An Examination of goog.base() by Michael Bolin
    • Closure: The Definitive Guide by Michael Bolin
    • JavaScript Patterns by Stoyan Stefanov (see Chapter 6: “Code Reuse Patterns” for a detailed analysis of the pattern used to implement goog.inherits() – Classical Pattern #5–A Temporary Constructor)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Google Analytics setup instructions state: This tracking code snippet should be included in
This code snippet used to work. I think a recent update of Google Chrome
Is this possible? I inserted a simple test snippet like this <script type=text/javascript>//<![CDATA[ document.write('foo');
I was wondering what this snippet exactly does? (found here: http://code.google.com/p/google-app-engine-samples/source/browse/trunk/django_example/django_bootstrap.py ) # Make
This snippet of code always parses the date into the current timezone, and not
Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this
Edit: I put this snippet of code in jsbin: http://jsbin.com/eneru I am trying to
I've found this snippet of code on the net. It sets up an NSMutableArray
I'm using Guava-05-snapshot, with Sun's JDK 1.6 The code blows up executing this snippet:
When I typed this apparently innocent snippet of code: values.name gedit highlighted name as

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.