Harnessing the power of the Function Object
By, Rob Gravelle
The JavaScript language
can operate equally well within many of the major programming paradigms. The first programming model most students learn is Procedural Programming; so called because procedures (functions) are used to group similar functionality.
JavaScript also supports most of the features of the Object-Oriented (OO) model, such as encapsulation, modularity, polymorphism and inheritance. Perhaps not a pure OO language like Java, the proliferation of JavaScript Frameworks in recent years, as well as the inclusion of new functionality in later versions of JavaScript, have brought the language closer to true OO style. In this article, we explore the Function object and learn about its role in a lesser known style of coding called Functional Programming. Our specific area of focus is the Functional Programming concept of using Higher Order functions to improve code modularity. Ironically, JavaScript might be the most widely deployed Functional Programming language in use today, but most people are unaware of this fact. That's a shame, because the Functional Programming style is one of our best allies in writing well-structured and modularized code.Functional Programming: What It's All About
Functional Programming emphasizes the evaluation of expressions rather than the execution of commands. Tracing back to calculus mathematics, the main goal of Functional Programming is to prevent the inadvertent changing of already calculated values. As developers
know, the most likely cause of accidental variable modifications are functions that have access to global objects. The reason accessing of
global variables by multiple functions is inherently dangerous is that changing a global variable in part of a program can have unexpected effects in another part. Functional programming isn't a replacement for Object-Oriented and Pricedural/Imperative styles; each has a place in Web development

0 comments:
Post a Comment