- Mar 2020
-
www.knack.com www.knack.com
-
HTML
This should say "JSON".
-
scene_3 and view_69
These keys don't seem to agree with the image.
-
object_12
I believe this should say object_1 in order to match the image.
-
- Nov 2018
-
www.sitepoint.com www.sitepoint.com
-
map
The map operation is a classic example) of functional thinking. Here, the JavaScript
map
function takes an array of words (produced by the expressionstr.split(" ")
), and returns a new array by applying a function (bound to the argumentfn
) to each element of the input array. Thejoin
function then converts the new array to a single string, with a space character between the elements. -
fn
When this function
processWords
is called, the first argument should be a function.processWords
will pass that argumentfn
on to the built-in JavaScript functionmap
. -
capify
capify
is a function. It is being passed as an argument to the functionprocessWords
. -
treat functions as first-class objects
This means that functions can be assigned to variables, passed as arguments to other functions, and returned from other functions. In many ways it means treating functions just like any other type of data: numbers, strings, etc. Many programming languages do not have this flexibility.
-
}());
This entire code listing is a self-invoking function. In other words, the code defines an anonymous function (it has no name), follows the definition with
()
, which turns it into a call to the anonymous function, and wraps the whole thing in parentheses so that JavaScript will process it that way. This is a way of keeping things to a local rather than global scope without the need to name and call a function. Learn more. -
written to an object-oriented standard
Notice that this is the old-school JavaScript syntax for object-oriented code, dealing directly with prototypes. This differs from our metatypic approach to JavaScript syntax, which hides prototype details under more familiar class concepts.
-
the whole thing relies on a context that may or may not exist
In other words, the JavaScript code might not be running in a Web browser, or the browser's page might not contain a button with the
id
ofmain_button
. -
document object model (DOM)
The DOM is an object-oriented data model of the browser's current HTML page contents. It provides an interface for JavaScript code to manipulate the browser page. Learn more.
-
function getText
Notice that these functions are defined at global scope. They are not methods inside of a class definition.
-