0

This is the first time seeing this. I have looked this up and have not found anything pertaining to this syntax of $(()).

<script>
    'use strict';
    $(() => {
        // code goes here
    });
</script>
imparante
  • 503
  • 9
  • 21
  • Which bit are you confused about? The syntax for the anonymous function itself, or its use in jquery ready? – Clive Apr 09 '16 at 19:17
  • I am confused about what it is entirely. It looks similar to both an anonymous and ready function in jQuery at the same time. I have not seen this before. I do not understand how or why this would be used versus the more common jQuery practices: http://www.sitepoint.com/types-document-ready/ – imparante Apr 09 '16 at 19:38

1 Answers1

3

This is, for the most part, the equivalent of:

<script>
    'use strict';
    $(function() {
        // code goes here
    });
</script>

Which, assuming the $ variable is assigned to the jQuery library, will be a "normal" document ready callback function.

You can learn more about arrow functions here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

scott113341
  • 109
  • 4
  • So I guess the lack of the function keyword was throwing me off. I have not found any documentation discussing this type of usage. – imparante Apr 09 '16 at 19:46
  • To be clear, Arrow functions are NOT jQuery-specific, so you may not see anything in the jQuery documentation about them. Arrow functions are a new syntax for anonymous functions in JavaScript. – scott113341 Apr 09 '16 at 19:53
  • 2
    More precisely, this is the equivalent of `$(function () { ... }.bind(this))`. jQuery is infamous for using *dislexical* `this`. – Estus Flask Apr 09 '16 at 20:22