0

考虑以下代码:

function Coord(x, y) {
    this.x = x;
    this.y = y;
}

function Ellipse() {
    this.Text = Text;
    this.Cx = Cx;
    this.Cy = Cy;
    this.Rx = Rx;
    this.Ry = Ry;
}

现在在函数中Ellipse而不是 usingCxCy。我想Coord为每一对实例化函数以实现如下所示:

function Coord(x, y) {
    this.x = x;
    this.y = y;
}

function Ellipse() {
    this.Text = Text;
    Coord C = new C(); // where C has its own properties x and y
    Coord R = new R(); // where R has its own properties x and y
}
4

1 回答 1

0

尝试这个:

function Coord(x, y) {
    this.x = x;
    this.y = y;
}

function Ellipse(text, cx, cy, rx, ry) {
    this.text = text;
    var c = new Coord(cx, cy);
    var r = new Coord(rx, ry);
}

我不知道你是怎么想的,Coord C = new C()但这是绝对错误的。JavaScript 变量没有类型。

另外,您从哪里得到Text, Cx,Cy等?它们不应该作为参数传递给构造函数吗?

于 2013-03-06T11:18:03.880 回答