Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>(function(parameterOne, parameterTwo) {</code></p> <p>Does not make sense as you're not passing these arguments in the end. Also, looks like you're immediately trying to create anonymous code block - makes sense in some cases, but you don't need to do it unless you're trying to protect global scope from whatever happens inside this code block.</p> <pre><code> functionOne = function(...) { ... }, </code></pre> <p>This is a named function similar to <code>var functionOne</code> will be useful only inside parent function or constructor. </p> <pre><code> functionTwo: new function() { }, </code></pre> <p><strong>UPDATE:</strong> Doesn't really make sense as you're trying to create instance here. You can definitely immediately instantiate what you have inside that function declaration (it is same as declaring a func. first and then using operator <code>new</code>) but in this case what you get is an object not a function. Try:</p> <pre><code>var f = function() {}; console.log(f); // "function" var f = new function() {} console.log(f); // "objest" </code></pre> <p>That object is the instance of your constructor function.</p> <pre><code> this.functionThree = function(...) { } </code></pre> <p>this is a method of a class. Once you instantiate the class using operator <code>new</code>, you can access it from outside of the instance. Also when you use <code>this.</code> inside a class, remember that every time you instantiate a class, it will reserve memory for this value. When the variable is different for these instances than it's okay, but if it's a method, you're better of adding it to the constructor prototype, this way it's only declared once and new memory chunks are not reserved for it.</p> <pre><code>})() </code></pre> <p>here you would ordinarily pass params you request inside, e.g. <code>parameterOne, parameterTwo</code></p> <pre><code>(function(parameter) { functionFour = function(..) { }, .... })(document) </code></pre> <p>This is a way to pass context or any objects to this anonymous code block. In this case it looks like a plug in that takes window.document but it can also take any other part of DOM. For instance, if you want to select all tags <code>a</code> and receive <code>document</code> as param, it will iterate through all links in window.document, but if you pass <code>$('#somediv')</code>, this plugin will iterate through links only inside div with this id.</p> <pre><code>(function($) { $.fn.myCustomPlugin: function(...) { } })(jQuery) </code></pre> <p>This is a good way to make sure that in the code inside $ is a jQuery object. Thing is that in Chrome for example there's already a native function <code>$</code>, or in some production sites <code>$</code> may be a Prototype JS function. But in the example inside you make sure that var <code>$</code> is not native <code>$</code> or not Prototype.</p> <p>In general, you should not use <code>(function() {...})()</code> liberally -- this is only used in specific cases when you're protecting global environment as I mentioned above. </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