Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Issues
  • #20011
Closed
Open
Issue created Jun 01, 2016 by Administrator@rootContributor

v5: JS constant declaration / minification

Created by: pvdlg

Most of the constant in javascript modules are declared as properties of constant objects, i.e.:

const ClassName = {
  BACKDROP : 'dropdown-backdrop',
  DISABLED : 'disabled',
  OPEN     : 'open'
}

Once minified, these constants are not mangled (for example search for 'BACKDROP' in bootstrap.min.js) because uglify, by default doesn't mangle object keys (I didn't find a safe way to have Uglify mangling objects keys).

Defining a variable as a constant make it a read-only reference, however defining an object as a constant make this object reference read-only, but not its keys. See const. As all the variables declared this way in Bootstrap are read but never reassigned, therefore really used as constants, I would imagine that the original intent was to make the actual variable a constant, rather than its wrapping object.

Declaring these constants directly rather than as object key would:

  • allow mangling of the variables declaration and their references (smaller minified file, faster parsing)
  • be more consistent with the intention (as I understand it) of declaring read-only variable

Is there a reason for which the constants are declared as object keys rather than directly as a constant ?

If not, I would like to propose a PR that would change the code example above into:

const CN_BACKDROP = 'dropdown-backdrop'
const CN_DISABLED = 'disabled'
const CN_OPEN = 'open'

The CN_ naming convention for Class name (or S_ for selectors, E_ for events) would maintain the readability of the current implementation (I imagine readability might be the reason for this choice ?).

Am I missing/misunderstanding something ? Would you consider such PR ?

Assignee
Assign to
Time tracking