我在 javascript 中创建了这段代码:
function Shape() {}
Shape.prototype.name = "Shape";
Shape.prototype.toString = function() {
result = [];
if(this.constructor.uber) {
result[result.length] = this.constructor.uber.toString();
}
result[result.length] = this.name;
return result.join(', ');
}
function twoDShape() {};
twoDShape.prototype = new Shape();
twoDShape.prototype.constructor = twoDShape;
twoDShape.uber = twoDShape.prototype;
twoDShape.name = "twoD Shape";
var a = new twoDShape();
console.log(a.toString());
我不知道为什么,但是当我运行它时,Firefox 冻结了。我一直在努力解决这个问题。我的猜测是我的代码中应该有一个无限循环,它存在于 if 条件的某个地方,但我没有找到它。有人可以帮我摆脱这种头痛。谢谢!