![]() You can buy a print version of this book, with an extra bonus chapter included, printed by No Starch Press at /ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN= &linkCode=as2&tag=marijhaver-20&linkId=VPXXXSRYC5COG5R5. The second edition of Eloquent JavaScript was made possible by 454 financial backers. Pixel art in Chapter 16 by Antonio Perdomo Pastor. Game concept for Chapter 15 by Thomas Palef. Regular expression diagrams in Chapter 9 generated with by Jeff Avallone. Object with on/off switch (Chapter 6) by Dyle MacGregor. Octopuses (Chapter 2 and 4) by Jim Tierney. Sea of bits (Chapter 1) and weresquirrel (Chapter 4) by Margarita Martínez and José Menor. Computer (introduction) and unicycle people (Chapter 21) by Max Xiantu. The illustrations are contributed by various artists: Cover by Wasif Hyder. So when you call the returned function via isNotNaN() it can still access that original func parameter that is set to the isNan function.1 Eloquent JavaScript A Modern Introduction to Programming Marijn HaverbekeĢ Copyright 2014 by Marijn Haverbeke This work is licensed under a Creative Commons attribution-noncommercial license ( All code in the book may also be considered licensed under an MIT license ( /licenses/mit). You'll notice that the returned function references the func parameter. Regarding how the negate() function works, it relies on the concept of "closures", which means that functions declared inside negate() have access to its variables and parameters even after negate() completes. To oversimplify, it is a constant provided to you by the JS environment. "I just don't understand.where the variable/value for NaN comes from" calls isNotNan() and passes it NaN as a parameter, and the result is written out to the document. So then the line: document.writeln(isNotNaN(NaN)) ![]() Now the negate() function actually creates and returns another function, so after that line runs isNotNan references that returned function, which means you can call it as isNotNan(someVal). That parameter isNan is actually a function as described by MDN, but negate() would accept any function as a parameter, you could say for example var isNotFinite = negate(isFinite). declares a variable isNotNan that is assigned equal to the result of a call to the negate() function, passing isNan as a parameter. I think xdazz pretty much covered it, but since you said you still don't get it maybe it would help to hear the explanation in somebody else's words.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |