Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First way is when you put <code>"use strict";</code> pragma at first line of .js file. So EVERYTHING in that file will be strictly evaluated.<br> There is nothing inherently wrong with that. Sooner or later all browsers will make 'old js code' deprecated. Only real drawback might be potentially breaking old code if you use it.</p> <p>Second way might be an object like this:</p> <pre><code>var contName = new function () { "use strict"; this.tmp; // public temp var var tmp; // private tmp, propagate thru all! var f = this; // to call contName.functions when this = html or other object var o = this; // to create objects. f.rnd = function rnd (range) { return Math.floor(Math.random() * range); }; function private1 () { // can be called only inside of contName var x = tmp; // can see all outer private vars this.tmp; // !== outer this.tmp var y = this.rnd(x); // will not work var y = f.rnd(x); // work } o.Pixel = function (x, y, z, col) { this.x = x || 0; this.y = y || 0; this.z = z || 0; this.color = col || 0; }; </code></pre> <p>tmp = new o.Pixel(300, 300);</p> <pre><code>} // end </code></pre> <p>That code allows you to have "private" variables. Note that f as also a 'private' var. </p> <p>Usage is simple:</p> <pre><code>var rvar = contName.rnd(5); var obj = new contName.Pixel(300, 300) </code></pre> <hr> <p>Third way might be T.J.Crowder's, fourth is Doug Crockford's ... These are just different ways for emulating something that's not yet officially present in a language.</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. 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