//第一种方式
Math.power = Math.pow;
Math.pow = function(x, y) {
if (x != 0) {
return Math.power(x, y);
} else {
return 0;
}
}
//if (Math.power == null) { //Solution: 如果Math.power 已经在别的地方定义过了,再次这样重新定义,会导致循环引用
Math.power = Math.pow;
Math.pow = function(x, y) {
if (x != 0) {
return Math.power(x, y);
} else {
return 0;
}
}
//}
//第二种方式
Math.power = Math.pow;
Math.pow = function(x, y) {
if (x != 0) {
return Math.pow(x, y);
//return Math.power(x, y);//Solution:启用这句可以解决问题.
} else {
return 0;
}
}
上面我写了两种方式来制造这种异常.然后把里面注释的语句启用.就可以避免这种异常.