标签:style blog http io color ar java for sp
代码信息来自于http://ejohn.org/apps/learn/。
var obj = {}; var fn = function(){}; console.log( obj && fn );//true
var obj = {}; var fn = function(){}; obj.prop = "some value"; fn.prop = "some value"; console.log( obj.prop == fn.prop, "都是对象,都有属性." );
function getElements( name ) { var results; if ( getElements.cache[name] ) { results = getElements.cache[name]; } else { results = document.getElementsByTagName(name); getElements.cache[name] = results; } return results; } getElements.cache = {}; console.log( "返回的结果: ", getElements("pre")); ///HTMLCollection [ <pre> ] console.log( "返回和缓存完全相同", getElements("pre") === getElements.cache.pre); //true
当我们访问的通过一系列操作获取到的内容,通过缓存先前的结果,可以提高性能。
function isPrime( num ) { var prime = num != 1; for ( var i = 2; i < num; i++ ) { if ( num % i == 0 ) { prime = false; break; } } return prime; } console.log( isPrime(5)); console.log( isPrime.cache[5] );
标签:style blog http io color ar java for sp
原文地址:http://www.cnblogs.com/winderby/p/4063409.html