MyClass = function () {
    this.A = 1;
}

MyClass.prototype.X = function () {
    this.B = 2;
}

MyClass.prototype.Y = function () {
    this.Z = function () {
        this.C = 3;
    }
}

/* 内部对象的 this ? */
obj = new MyClass();
alert(obj.A);        //1

obj1 = new obj.X();
alert(obj1.B);       //2

obj2 = new (new obj.Y()).Z();
alert(obj2.C);       //3

/* 所属对象的 this ? */
obj = new MyClass();
obj.X();
obj.Y();
obj.Z();
alert(obj.A); //1
alert(obj.B); //2
alert(obj.C); //3

posted on 2012-03-19 16:17  万一  阅读(1988)  评论(2编辑  收藏  举报