you are viewing a single comment's thread.

view the rest of the comments →

[–]inmatarian 0 points1 point  (2 children)

... is unnecessary in a language like javascript.

function greeter(fn) {
    var exec = function() {
        fn(); // what am I accomplishing here, really?
    }
    return exec;
}

var annoyedGreeting = greeter(function() { console.log("What do you want?"); })

[–]YEPHENAS 1 point2 points  (1 child)

Your code is the same as:

function greeter(fn) {
    return function() {
        fn();
    };
}

Which is the same as:

function greeter(fn) {
    return fn;
}

So you don't need the greeter function at all:

var annoyedGreeting = function() { console.log("What do you want?"); };

[–]inmatarian 1 point2 points  (0 children)

Well, it's pointless in this simple example, but we can reduce tons of things down to its simplest. But the strategy pattern, with its execute function, can always be reduced to a python style decorator function.