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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:22:24+00:00 2026-06-12T18:22:24+00:00

In the book WebGL – Up and Running a custom geometry is constructed, in

  • 0

In the book “WebGL – Up and Running” a custom geometry is constructed, in a very undramatic way. However, the second to last line of code raised my eyebrows. The code is as follows:

Saturn.Rings = function ( innerRadius, outerRadius, nSegments ) {

    THREE.Geometry.call( this );

    var outerRadius = outerRadius || 1,

    ...snip snip snip...


    this.computeCentroids();
    this.computeFaceNormals();

    this.boundinSphere = { radius: outerRadius };
};

Saturn.Rings.prototype = new THREE.Geometry();
Saturn.Rings.prototype.constructor = Saturn.Rings;

My question is: why does he use a constructor instance in the prototype chain? Why can’t Saturn.Rings.prototype just be a new blank object that inherits from THREE.Geometry.prototype? Shouldn’t all stuff worth inheriting be positioned in THREE.Geometry.prototype? Why does he make the prototype an instance of the Geometry-constructor? (I am aware that the prototype chain is still correct, as the new prototype gets to inherit from THREE.Geometry‘s prototype).

Also, in the second line in the code above, instances of Saturn.Rings are put through the THREE.Geometry constructor. Thus, they get all they could dream of from THREE.Geometry construction process. Thus, there is no need to do the same to their prototype.

Lets take a look at how a similar geometry is handled in three.js itself:

THREE.CubeGeometry = function ( width, height, depth, segmentsWidth, segmentsHeight, segmentsDepth, materials, sides ) {

    THREE.Geometry.call( this );

    ...snip snip snip...


    }

    this.computeCentroids();
    this.mergeVertices();

};

THREE.CubeGeometry.prototype = Object.create( THREE.Geometry.prototype );

Way neater. The only problem is that he forgets to set the prototype’s ‘constructor’-property to point back to THREE.CubeGeometry, but that’s another matter.

  • 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-12T18:22:26+00:00Added an answer on June 12, 2026 at 6:22 pm

    Calling the constructor is probably done for compatibility. Object.create() is a relatively new addition to JavaScript and is unsupported by some browsers released prior to the publication of ECMAScript 5 (such as IE8 and IE7). Just calling the constructor of another object is not enough for the object to inherit the other object’s prototype (demo). Certainly there are benefits to avoiding invoking the parent object’s constructor, but whether Object.create() is “Way neater” is debatable.

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

Sidebar

Related Questions

I'm reading the book 'Beginning F#', There's a short list for example code, to
The book uses this code to draw a checkerboard. The only problem I'm having
The book of CLR via C# has this line at page 76. When you
The book I've been reading about Django mandates heavy usage of a command line
I'm reading a book written by Julie Lerman on Code First. According to the
I'm very new to WebGL, but I'm getting close at understanding the basics. I'm
A book as the following example and explains that you won't see the line
The book I'm currently reading has me write the following code : -(IBAction)displaySomeText:(id)sender {
The book Agile development with Rails shows in the second chapter, that you can
The book of IronPython In Action has the following code to read python script

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.