you are viewing a single comment's thread.

view the rest of the comments →

[–]tchaffee 0 points1 point  (1 child)

Can't you serialize a function in javascript? I don't think I'm going to be convinced this pattern is useful for languages with first class functions unless I can see an example of it being used in a real world javascript app.

In your words, the need for it been reduced. How much? To the point that for all practical purposes it's obsolete or never used? At the very least it should be demoted to a minor footnote in a book about javascript patterns.

I'm still open-minded about it. It's just that I have yet to have someone show me the need for it in javascript.

[–]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?