1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

question about js file in xenforo

Discussion in 'XenForo Development Discussions' started by typostudy, Jun 3, 2013.

  1. typostudy

    typostudy Member

    I see many xenforo js files have below kind of format, I will take \js\xenforo\full\news_feed.js for example:
    Code:
    !function($, window, document, _undefined)
    {
         ...
        XenForo.register('a.NewsFeedItemHider', 'XenForo.NewsFeedItemHider');
    }
    (jQuery, this, document);
    Qustions:
    1. why put ! before function? what does
    Code:
    _undefined
    mean here?
    2.
    Code:
     XenForo.register('a.NewsFeedItemHider', 'XenForo.NewsFeedItemHider');
    what does this line mean here?
     
  2. Beardy

    Beardy Member

    Still fairly new to XenForo, but here's what I've gathered:

    Why put ! before function?
    As explained in this Stack Overflow post, the exclamation mark runs the function after it has been declared.

    What does '_undefined' mean here?
    From first glance, it just seems to be a placeholder variable and doesn't seem to do anything (feel free to correct me on that). Though this is just speculation, there could be something in the core XenForo code that requires four attributes be set (or perhaps it is for backward compatibility).

    Edit: this Presentation may shed some light on what is going on in the code.
     
    Last edited: Jun 3, 2013
  3. typostudy

    typostudy Member

    It is helpful. Thanks
     

Share This Page