Beginner JavaScript OOP vs Functional

前端 未结 5 1420
后悔当初
后悔当初 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:43

    Functional: You pass an object to the function and do stuff

    _.map([1, 2, 3], function(n){ return n * 2; });

    OOP: You call function on the object and do stuff

    _([1, 2, 3]).map(function(n){ return n * 2; });

    In both examples [1,2,3] (array) is an object.

    Example OOP reference: http://underscorejs.org/#times

提交回复
热议问题