A partial archive of https://discourse-mediawiki.wmflabs.org as of Saturday May 21, 2022.

Why use named functions as contructor of OOJS UI classes?

Osnard

I am just curious: Is there an important reason why all constructor method in OOJSUI are named?

E.g. in ve.ui.MWWikitextWarningCommand.js [1] it says:

ve.ui.MWWikitextWarningCommand = function VeUiMWWikitextWarningCommand() { ... }

Wouldn’t

ve.ui.MWWikitextWarningCommand = function() { ... }

be also working?

[1] https://github.com/wikimedia/mediawiki-extensions-VisualEditor/blob/0fcb567ebc1b782614d68b32f65a8539eb316bae/modules/ve-mw/ui/commands/ve.ui.MWWikitextWarningCommand.js#L15

jwbth

I’m not a OOUI developer, but wouldn’t anonymous functions make debugging harder? That’s usually the reason why named functions are advised. As for an OOUI user, it’s convenient for me to see the constructor names instead of nothing.

Tgr

Yeah, this used to be best practice for making call stacks readable. These days inferred function names are part of the standard and supported by most modern browsers, so maybe less important (although you get to control the function name this way).

Osnard

Thanks for the explanation