What task is best done in a functional programming style?

前端 未结 16 1780
-上瘾入骨i
-上瘾入骨i 2020-11-29 17:29

I\'ve just recently discovered the functional programming style and I\'m convinced that it will reduce development efforts, make code easier to read, make software more main

16条回答
  •  隐瞒了意图╮
    2020-11-29 17:48

    Show them jQuery's way of iterating over DOM elements:

    $(".magic-divs").click(function(){
        // FYI, in this context, "this" will be the element clicked on.
        alert("somebody clicked on " + this.id);
        this.hide();
    
    });
    
    $(".magic-divs").show();
    

    vs. how most google results for "javascript element by classname" do it:

    var arrayOfElements = // this is filled with the elements somehow
    for(var i=0,j=arrayOfElements.length; i

    Functional programming is useful in everyday stuff like the above!

    (note: I don't know if my example fits the exact definition of functional programming, but if it does, than functional programming is awesome)

提交回复
热议问题