3
基于if-else,switch或map的调节的性能
我想知道以下JavaScript中条件结构实现的性能。 方法1: if(id==="camelCase"){ window.location.href = "http://www.thecamelcase.com"; }else if (id==="jsFiddle"){ window.location.href = "http://jsfiddle.net/"; }else if (id==="cricInfo"){ window.location.href = "http://cricinfo.com/"; }else if (id==="apple"){ window.location.href = "http://apple.com/"; }else if (id==="yahoo"){ window.location.href = "http://yahoo.com/"; } 方法2: switch (id) { case 'camelCase': window.location.href = "http://www.thecamelcase.com"; break; case 'jsFiddle': window.location.href = "http://www.jsfiddle.net"; break; case 'cricInfo': window.location.href …