Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Just how does this bit of Javascript work

I one of my current projects I am using Split.js. Given the complexity of that project I find it necessary to take the original SplitJS code and fork it one of my own ES6 classes. The process has gone smoothly but this line

const defaultGutterStyleFn = (dim, gutSize) => ({ [dim]: `${gutSize}px` })

has got me stumped. I am guesssing that defaultGutterStyleFn returns a CSS rule that bears the form {dim:NNpx} where

  • dim is probably a dimension (height, width etc)
  • gutSize is a numeric value

However, I do not see how the code I have quoted above would possibly doing this. Perhaps I have stumbled upon a JS/ES feature that I don’t know? I’d much appreciate any help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If is just a fancy way how to write something like this:

function defaultGutterStyleFn(dim, gutSize) {
    const result = {};
    result[dim] = gutSize + 'px';
    return result;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading