Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Point #1</strong>: If you want all the member variables from an object, use <code>for(.. in ..)</code>:</p> <pre><code>// output all keys and values for(key in myclassins) { console.log(key, myclassins[key]); } </code></pre> <p>Note that functions are first-class variables in JavaScript, so if you only want to enumerate the non-function member variables of <code>myclassins</code>, do:</p> <pre><code>// output all keys and values that are not functions for(key in myclassins) { if(!myclassins[key] instanceof Function) { console.log(key, myclassins[key]); } } </code></pre> <p><strong>Point #2</strong>: In JavaScript, the <code>this</code> variable is called the <em>context</em> of the function. The context may change -- when you call <code>setInterval</code>, for example, it causes the anonymous function to run with a context of <code>this == window</code> instead of the context of the current object. If you want to refer to the context of the current object, store it in another variable at the start of your constructor, like <code>var self = this;</code>, and then refer to <code>self</code> in the anonymous <code>setInterval</code> function when you want to refer to the object.</p> <p>This works because JavaScript supports <em>closures</em>, which means that when you define a function, that new function has access to all the variables that current exist in the current scope, including (in this case) <code>self</code>.</p> <p><strong>Notes</strong>:</p> <ul> <li><p>JavaScript is <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Details_of_the_Object_Model#Class-Based_vs._Prototype-Based_Languages" rel="nofollow">prototype-based, not class-based</a>. It can be a difficult distinction to understand, and not one that has any bearing on your exact code. However, you may find people correcting you if you say "JavaScript class".</p></li> <li><p>It's traditional to initial-caps CamelCase the names of types, e.g., instance <code>fooBar</code> is of type <code>FullTimeEmployee</code> (not <code>fullTimeEmployee</code> or <code>fulltimeemployee</code>).</p></li> </ul>
    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. This table or related slice is empty.
    1. 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