javascript - Should I use immutability for objects with functions only? -


i use immutable.js in project , try not use plain js structures.

but i'm not sure if makes sense convert objects contain functions immutable ones.

let's have mathutility.js:

export default {   sum (a, b) {     return + b   },   min (a, b) {     return - b   }  //etc. more utils methods } 

is sense instead:

export default immutable.fromjs({   sum (a, b) {     return + b   },   min (a, b) {     return - b   }  //etc. more utils methods }) 

from pov it's not data object (hard split data functions in js time time) there no point that, i'm not sure.

thanks

no, don't see value in converting these immutable objects. in fact, there's big drawback: can no longer call these utility functions directly.

using example:

var utils = immutable.fromjs({   sum (a, b) {     return + b;   },   min (a, b) {     return - b;   } });  utils.sum; // => undefined utils.get('sum'); // => function utils.get('sum')(1, 2) // => 3 

that's pretty awkward imho.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

Ansible warning on jinja2 braces on when -

html - How to custom Bootstrap grid height? -