Beginner JavaScript OOP vs Functional

前端 未结 5 1418
后悔当初
后悔当初 2021-01-30 11:50

I\'m just starting to research different programming styles (OOP, functional, procedural).

I\'m learning JavaScript and starting into underscore.js and came along this s

5条回答
  •  失恋的感觉
    2021-01-30 12:32

    FP

    In FP, a function takes inputs and produces output with the guarantee that the same inputs will yield the same outputs. In order to do this, a function must always have parameters for the values it operates on and cannot rely on state. Ie, if a function relies on state, and that state changes, the output of the function could be different. FP avoids this at all costs.

    We'll show a minimum implementation of map in FP and OOP. In this FP example below, notice how map operates only on local variables and does not rely on state -

    const _ = {
                     // 

提交回复
热议问题