funjs / book-source Goto Github PK
View Code? Open in Web Editor NEWThe example source code for the book Functional JavaScript by Michael Fogus, published by O'Reilly
License: Other
The example source code for the book Functional JavaScript by Michael Fogus, published by O'Reilly
License: Other
FWIW, my fork contains CoffeeScript variants of the first three chapters. I'd welcome contributions from the later chapters if anyone else is working through through the text in this manner (i.e., converting to idiomatic CS).
There is an error on page 32. It is stated that the following function returns the global Window object, but it returns the object b:
var bFunc = function () { return this; }
var b = { name: "b", fun: bFunc };
b.fun()
console.log(b.fun()); gives:
Object {name: "b", fun: function}
Im not sure if this is the correct implementation of the truthy function as 0 & ' ' are both falsey values in javascript which is confusing..
I think you should use the boolean operator to tell if the value is truthy
function truthy(x){ return !!x; }
Hi, on page 94 you explain the right vs left currying techniques, but in the example you provide there isn't much 'right or left' action going on. That only happens later on, specially with the blueGreenish
example on page 99.
My understanding is that on page 94 the difference actually happening inside the div function, and the order of the parameters is not that relevant (from a curry point of view), where on the blueGreenish
you can really see the currying from the rightmost argument.
I think the 'To Curry Right, or To Curry Left' section would be easier to understand on first read if the 'HTML Hexadecimal values with specific hues' example was used instead
Any plans to include an MIT License with the source so any code snippets can be reused in production code?
Awesome book. I love it.
About your helper predicates, existy() and truthy(), couldn't you just do:
function existy(x) { return x != null; }
function truthy(x) { return !!x; }
Granted, it doesn't really illustrate the idea of composing functions from functions but is more succinct, I think.
It would be great if all the chapters worked right out of the box as node modules, so you can play with them at the node.js REPL or require() them into a temporary javascript file to play with.
For example, Chapter02 is dependent on truthy()
and existy()
and underscore.js, but you need to modify the chapter to make these available in chapter02.
Caveat: To make it easy to play with at the REPL, you may need to do something with _.noConflict since the node REPL uses _
to store the previous REPL value.
that second example ( I think ) on chapter 2
var bFun = function(){ return this}
var b = {name : 'b' , fun : bFun }b.fun(); // returns b not the global window object .
just a comment about the ordering of the book... truthy is needed before its shown or discussed in the book. :) might consider ordering that sooner or at least noting where truthy is coming from otherwise comparator function doesn't work before you know the truthy!
to the function sort: -1 means LT, 1 means GT and 0 means EQ. To the comparator function: -1 means the first test to pass, 1 means the opposite of first test, and 0 means both tests failure. Comparator drifts away from what really matters ordinal position.
if the first test has predicate lessThan and x is less than y, ok
but if the first test has the pedicate greaterThan and x is greater than y, comparator returns -1 meaning GT, and sorts only accepts -1 to mean LT.
Besides comparator only accepts 2 parameters predicates, isPrime, isOdd, isEven are one parameter predicates. Don't say they can be passed to comparator, they do not fit comparator contract.
function complement(fn){ return (function(num){ return !fn(num); }) }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.