Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It will be <code>Particle.Velocity.X</code>. Not specifically because of the scope of <code>this</code> but because you did this:</p> <pre><code>this.Velocity = new Vector(0,0,0); </code></pre> <p>You're assigning to the <code>Velocity</code> property of the <code>Particle</code> object.</p> <p>But <code>this</code> works differently in javascript so it's worth spending some time understanding it. It's not bound directly to the object where it's declared/written but rather bound at run time to different things depending on how the function/method is called.</p> <p>For example, consider the following:</p> <pre><code>var foo = {}; foo.name = 'Frank'; foo.say = function () {alert('My name is' + this.name)} foo.say(); </code></pre> <p>as you would expect, the code above alerts "My name is Frank". But, if you do this:</p> <pre><code>var bar = {}; bar.name = 'Benny'; bar.say = foo.say; bar.say(); </code></pre> <p>the code above will alert "My name is Benny". That's because <code>this</code> is bound to the last word/name before the dot. So even if the function was originally declared in the context of <code>foo</code>, once it's called with <code>bar</code> as it's container object the <code>this</code> inside it will refer to <code>bar</code>.</p> <p>For a complete description of how <code>this</code> works in javascript see my answer to this other question: <a href="https://stackoverflow.com/questions/13441307/how-does-the-this-keyword-in-javascript-act-within-an-object-literal/13441628#13441628">How does the &quot;this&quot; keyword in Javascript act within an object literal?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload