question about js file in xenforo

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?
 
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:
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.

It is helpful. Thanks
 
Back
Top Bottom