Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>Your thinking is close in that next_item_id will always be 1, but it's generally not recommended to pollute the global namespace. Instead, wrap it in an anonymous function:</p> <pre><code>(function() { var next_item_id = 1; function Item(itemName) { //Use "this" to apply the property to the instance only this.item_name = itemName; this.item_id = next_item_id++; } var Item1 = new Item('Desktop'); var Item2 = new Item('Laptop'); var Item3 = new Item('Monitor'); })() </code></pre></li> </ol> <p>Also, as in Java, the general best practice in Javascript is to use camelCase rather than under_scores. Constructors are generally in UpperCamelCase. Examples:</p> <pre><code>Array //UpperCamelCase Object.prototype.toString //toString is camelCase </code></pre> <ol> <li><p>This question is ambiguous, and, depending on the interpretation, there can be a number of possible answers. <code>next_item_id</code> is a "var" declared inside a function and naturally has an internal <code>[[DontDelete]]</code> and <code>[[DontEnum]]</code> flag. If it's a "var" and we're not using "this" as shown in my modified code, the variable is inherently not accessible outside of the function or its nested functions and therefore cannot be modified. You can use the non-standard <code>const</code> or you can create an object and use Object.defineProperty to create a setter that returns false assuming an ES5-compatible environment, etc.</p></li> <li><p>Functions are objects in Javascript. All objects can have "properties."</p></li> </ol>
    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.
    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