composi / core

A JavaScript library for creating websites, PWAs and hybrid apps.
MIT License
27 stars 2 forks source link

[??] document use with expression functions #4

Closed brodycj closed 5 years ago

brodycj commented 5 years ago

for example (not tested):

const Title = (greet) => (
  h(
    'nav',
    {
      class: 'heading'
    },
    [
      // h(...)
    ]
  )
)

more functional, less imperative

rbiggs commented 5 years ago

Yes, that pattern works, but it's harder to debug in the browser console because the function is anonymous.

brodycj commented 5 years ago

I thought that modern JS engines would detect this kind of a pattern as a function declaration (Babel JS seems to do this), oh well. Closing for now.

rbiggs commented 5 years ago

To be honest, I do use the pattern occasionally myself. But I tend to use named functions as much as possible. I know it's fashionable for devs these days to use arrow functions as much as possible. I prefer to use them for what they were designed for: lambdas.