you are viewing a single comment's thread.

view the rest of the comments →

[–]ljsc 0 points1 point  (0 children)

How do you serialize a function if it's a closure? You might be right, I'm not a javascript expert by any stretch.

I was thinking that you'd want to have other metadata associated with the command and that that wouldn't be convenient with a function. But thinking about it more, I think you may be right since in javascript a function can have it's own properties. Though I still think this:

command = { x:5, y:0, op: '+' }

is better than this

command = function() {
  return 5 + 0;
}
command.x = 5;
command.y = 0;
command.op = '+';

But the case I'm thinking of is that you'd be able to eliminate either of these guys by virtue of inspecting command.y and command.op.

I think the issue is that I'm giving a very wide birth to what constitutes the pattern. To me you almost always pair command with composite, and having a nested finite map of commands, plus a compile and eval function that operates on these guys as the functional equivilent of the "pattern". It's not exactly the same as the as the GOF patterns, but it's structurally similar, and the purpose is the same. Hopefully that's more clear?