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

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -