function randomColor() {
var rand = Math.floor(Math.random() * 0xFFFFFF).toString(16);
if(rand.length === 6) {
return rand;
}else {
return randomColor();
}
}
当这个函数名改变的时候,里面的函数名也要随之改变,若是引用次数一多,修改就很麻烦,出现了耦合现象
这样就用到arguments.callee引用即可,避免耦合
function randomColor() {
var rand = Math.floor(Math.random() * 0xFFFFFF).toString(16);
if(rand.length === 6) {
return rand;
}else {
return arguments.callee();
}
}