I have some questions about the exercise # 1 of John Reciig about this ceremony
-
what is the purpose of the second last line
getElements.cache = {}; Does it accumulate thereturn result in an array?If my guess (1) is correct, is it just holding
return result , because the code in the "f" section of the function > GetElements.cache [name] = results; ?When I play with the code in the tutorial in the console, I get the result from the line
GetElements.cache [name] = "to" section , but Still the same result was achieved, as it was there - that is, he told me that there were 76 elements, therefore, what is the purpose of this linegetElements.cache [name] = result Not necessary for?There is no significance for the fact that, in the "F" section of the function, line
getElements.cache [name] = the sequence of results Is replaced by, ifsection, where it saysresult = getElements.cache [name]Finally, a pre-defined function in
cache javascript? I can not find it in the documentationfunction getElements (name) {var results; If (getElements.cache [name]) {Results = getElements.cache [name]; } And {result = document.getElementsByTagName (name); GetElements.cache [name] = Results; } Return results; } GetElements.cache = {}; Log ("found element:", getElements ("pre"). Length); A) Second from the last line, determines that the property "cache" on the object is " GetElements is an object originally to start that property.b) It will be a cache, think of getElements as an object and the cache is a hash which is catching on the results.
c) Yes, you'll still get the same result because the cache is just caching, this is not changing anyway, it will only speed things up potentially.
d) Yes, the cache is caching a result, removing the result of the second cache.
e) No This is a custom property that was defined for "getElements", any number of these can be defined with different names.
Comments
Post a Comment