Functional JavaScript Notes

Source: Internet
Author: User
Tags variable scope clojurescript

Functional JavaScriptDirectory
  • 1 Get Started with FP
  • 2 first-class Functions and applicative programming
  • 3 Variable Scope and Closures
  • 4 High-order Functions
  • 5 function-building Functions
  • 6 recursion
  • 7 Purity, immutability and policies for change
  • 8 flow-based Programming
  • 9 Programming without Class
  • Ten Appendix
Get Started with FP
    1. CSV Parse:
      return _.reduce (str.split ("\ n"), function (table, row) {
      Table.push (_.map (Row.split (","), function (cell) {return Cell.trim ();})); return table;}, []); };
    2. The author is the author of Clojurescript?
first-class Functions and applicative programming
    1. Return _.reduceright (arguments, function (truth,f) {return truth && f ();}, True);
    2. Pass NULL as the first argument to apply: This means that this refers to the global object ...
    3. P44 Traditional SQL Select actually corresponds to project in the relational algebra
    4. JS's lambda syntax is too cumbersome to write FP-style code that brings trouble
      1. Restrict (Project (as (library, {ed: ' Edition '), [' Title ', ' ISBN ', ' edition ']),
        function (book) {return book.edition>1;});
Variable Scope and ClosuresHigh-order Functionsfunction-building Functions
    1. function partial (fun/*, Pargs */) {
      var pargs = _.rest (arguments);
      return function (/* arguments */) {
      var args = Cat (Pargs, _.toarray (arguments));
      Return fun.apply (fun, args);
      } }
recursion
    1. Trampoline (Avoid mutual-recursive overflow):
      1. function even (n) {if (n==0) return true; else return Partial1 (odd , n-1); }
        1. ==> odd (20000001) () () ... ();
      2. Function Trampoline (fun/*, args */) {
        var result = fun. Apply (fun, _.rest (arguments)); Here we go.
        while (_.isfunction (result)) result = result ();
        return result; }
    2. generator (lazy infinite sequence)
      1. head-tail () abstraction, where tail encapsulates the calculation of the remaining series
      2. function Gentake (n, Gen) {
        var dotake = function (x, g, ret) {if (x==0) return ret; else return partial ( Dotake, X-1, Gentail (g), Cat (ret, Genhead (g)));
        return trampoline (Dotake, N, Gen, []);
Purity, immutability and policies for change
    1. Object#freeze = Deepfreeze
    2. API: Let object modification method return new Object instance
flow-based Programming
    1. _.chain
    2. Lazychain
      1. thunk:a function waiting to be called
      2. #force ()
    3. JQuery $. Deferred ()
    4. Pipelining
    5. Action (Monad): Flowing in context?
      1. Lift
      2. Actions
Programming without Class
    1. Mixins
      1. var polytostring = dispatch (function (s) {return _.isstring (s)? s:undefined;}, ...
    2. var mymixin = {
      Setvalue:function (v) {... this._value = v; this.notify (Oldval, v);}
    3. _.extend (Myclass.prototype, mymixin);
    4. var CAS = function (val) {Myclass.call (this, Val);}
      1. var casmixin = ...
Appendix
    1. Underscore-contrib
    2. RxJS
    3. Bilby ' s Multimethods
    4. Allong.es:support for stateful iterators
    5. *reducers:inspired by Clojure ' s reducer
    6. Clojurescript (the author wrote "The Joy of Clojure"?) )
    7. Coffeescript
      1. Literate programming
      2. Varargs
      3. List understanding
      4. Deconstruction Assignment
    8. Roy:inspired by ML
    9. ELM (+ + + not required for string stitching): FRP

Functional JavaScript Notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.