The code information comes from http://ejohn.org/apps/learn/.
are functions and objects not very similar?
var obj =varfunction&& fn); // true
var obj =varfunction= "Some value"= "Some value"= = Fn.prop, "All objects, all have attributes.");
Can I store the returned results in the cache?
functiongetelements (name) {varresults; if(Getelements.cache[name]) {results=Getelements.cache[name]; } Else{Results=document.getElementsByTagName (name); Getelements.cache[name]=results; } returnresults;} Getelements.cache= {}; Console.log ("Returned results:", getelements ("pre"));///htmlcollection [<pre>]Console.log ("Return and cache are identical", getelements ("pre") = = = GetElements.cache.pre);//true
When we access the content obtained through a series of operations, the performance can be improved by caching the previous results.
Title: Modify this code so that it can cache the results
function IsPrime (num) { var prime = num! = 1; for var i = 2; i < num; i++ ) { if (num% i = = 0 ) {false; Break ; } } return Prime;} Console.log (IsPrime (5)); Console.log (isprime.cache[5]);
JavaScript Advanced Knowledge Analysis-functions as objects