Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Scope is a tricky thing, and here are the basics.</p> <p>The only scope is function scope. Variables declared in a function stay in the function. Variables declared outside of a function are in global scope. Global variables are to be avoided though, as they're bad style.</p> <p>Functions are objects that don't have a home. You can only depend on the value of <code>this</code> in two circumstances:</p> <ul> <li>You called the function like this: <code>functionname.call(context, params)</code>, where context is the value of <code>this</code></li> <li>Your function is part of another object. <code>this</code> will be the object it's a part of <ul> <li>Note: if the function is detached from the function, all bets are off</li> </ul></li> </ul> <p>If a function is called in this way: <code>functionname(params)</code>, then <code>this</code> will be whatever this was in the calling scope. It's kind of weird though, so if you're going to use this, be sure you know what it is.</p> <p>You should assume that <code>this</code> will never refer to the global scope, and you should never use <code>this</code> in the global scope.</p> <p>I would use some kind of packager to avoid using the global scope. I use ender.js, and it's nice because the default packages are pretty similar to jQuery, so there's a small learning curve.</p> <p>Douglas Crockford is the man at explaining JavaScript:</p> <p><a href="http://javascript.crockford.com/" rel="nofollow">http://javascript.crockford.com/</a></p>
    singulars
    1. This table or related slice is empty.
    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