... | ... | @@ -99,30 +99,30 @@ There should be no space between the name of a function and the `(` (left parent |
|
|
This convention works well with JavaScript because in JavaScript, functions and object literals can be placed anywhere that an expression is allowed. It provides the best readability with inline functions and complex structures.
|
|
|
|
|
|
```javascript
|
|
|
function getElementsByClassName(className) {
|
|
|
var results = [];
|
|
|
walkTheDOM(document.body, function (node) {
|
|
|
var a; // array of class names
|
|
|
var c = node.className; // the node's classname
|
|
|
var i; // loop counter
|
|
|
function getElementsByClassName(className) {
|
|
|
var results = [];
|
|
|
walkTheDOM(document.body, function (node) {
|
|
|
var a; // array of class names
|
|
|
var c = node.className; // the node's classname
|
|
|
var i; // loop counter
|
|
|
|
|
|
|
|
|
// If the node has a class name, then split it into a list of simple names.
|
|
|
// If any of them match the requested name, then append the node to the set of results.
|
|
|
|
|
|
|
|
|
if (c) {
|
|
|
a = c.split(' ');
|
|
|
for (i = 0; i < a.length; i += 1) {
|
|
|
if (a[i] === className) {
|
|
|
results.push(node);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
return results;
|
|
|
}
|
|
|
if (c) {
|
|
|
a = c.split(' ');
|
|
|
for (i = 0; i < a.length; i += 1) {
|
|
|
if (a[i] === className) {
|
|
|
results.push(node);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
return results;
|
|
|
}
|
|
|
```
|
|
|
|
|
|
If a function literal is anonymous, there should be one space between the word `function` and the `(` (left parenthesis). If the space is omited, then it can appear that the function's name is `function`, which is an incorrect reading.
|
... | ... | |