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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:55:09+00:00 2026-06-15T07:55:09+00:00

Lets get into it. I’ve created a working Inertial Camera in Javascript, and while

  • 0

Lets get into it.
I’ve created a working “Inertial Camera” in Javascript, and while I’m very experienced in Javascript, I’m not experienced with prototyping in JS. I’m attempting to restructure my camera as follows, with the initial function constructor:

    function Inertia(subject, clickable) {
        this.subject = document.getElementById(subject);
        this.clickable = document.getElementById(clickable);
    }

And the prototype:

    Inertia.prototype = {
        subject : document.getElementById(''),
        clickable : document.getElementById(''),
        camera : { angleX : 85, angleY : 0, angleZ : 0, translateX : 0, translateY : -100, depth : 0, flag : 1 },
        mouse  : { x : 0, y : 0 },
        friction : 1,
        inertia : true,

        mouseEvents : {
            mouseDown   :   function( e ) {
                                var IS = this; // This will not work because I am two levels away from "this" being my object.

                                // cancel existing animation
                                clearTimeout((window).animation);

                                (IS).mouse.x = e.clientX;
                                (IS).mouse.y = e.clientY;
                                (IS).camera.flag = 0;

                                // begin logging history to animate from as a new history stack
                                (IS).tools.pushHistory('reset');
                            },

…
continued
…

My problem is that within my prototype object, I cannot access the root level elements such as mouse.x or mouse.y. What is the best method to access these elements for this specific instance of my “Inertia” class when creating a prototype like this? Is this the completely wrong idea?

I’m looking to understand the proper implementation of a prototype in this manner. I’ve looked up tutorials and articles on prototyping, and I’ve yet to see any examples address this nesting issue. They all use one level deep in their prototype so calling this is not problem.

I am attempting to have var IS equal the current object, so that in every instance of this inertial camera I will alter only that specific object. However, I am two levels deep within my prototype, so this keyword will not work. I could hardcode it equal to the variable name if I have only one instance of new Inertia(), but that is obviously not desirable.

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

    Properties usually go inside the constructor and methods on the prototype. I think you may be missing some concepts; there’s no point on creating (and duplicating) properties inside the prototype because properties are unique to the instance. If those variables are meant to be private the usual convention is to prefix it with an underscore:

    function Inertia( subject, clickable ) {
    
      this.subject = document.getElementById( subject );
      this.clickable = document.getElementById( clickable );
    
      // Private vars unique to each instance
      this._camera = { ... };
      this._mouse = { ... };
      this._friction = 1;
      this._inertia = true;
    
    }
    
    Inertia.prototype = {
    
      mouseDown: function( e ) {
        var self = this;
        // Now you can access and modify the private vars:
        self._mouse.x = e.clientX;
        ...
      }
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a singleton class (and lets not get into the discussion if that
I am generally not very fond of refactoring tools. No need to get into
I'm trying to get the value of my div into Javascript. It's a Drupal
this is my first post, so lets get into it: my problem is with
lets get straight to my problem, the code I have written here does not
In general we use biometrics in computer applications say for authentication. Lets get 2
Lets assume I get an HTML table as a string, and I want -
lets say you want to get all the columns of a table, but exclude
lets say i use jquery.get to retrive a website to string and how am
Lets say I have a selector $('.items') and I want to get every item

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.