以下是Douglas Crockford的The Good Parts的代码.
在大多数情况下,代码是有道理的.除此之外,我不明白这一行:
var walk_the_DOM = function walk(node, func) {
Run Code Online (Sandbox Code Playgroud)
因为看起来这个函数有两个名字 - walk_the_dom()和walk()
再往下看,你可以看到代码实际上是双向调用的,所以这两个名字实际上都引用了这个函数.
为什么这个函数有两个名字?
// Define a walk_the_DOM function that visits every
// node of the tree in HTML source order, starting
// from some given node. It invokes a function,
// passing it each node in turn. walk_the_DOM calls
// itself to process each of the child nodes.
var walk_the_DOM = function walk(node, func) {
func(node);
node = node.firstChild;
while (node) {
// walk() …Run Code Online (Sandbox Code Playgroud) javascript ×1