我有一个JS对象:MyObject = {
    InnerObj1 : function() {
        this.name = "HelloWorld";
    },     InnerObj2 : function() {
        this.accessObj1 = function() {
            //我要在这里访问到InnerObj1的name属性,这个应该怎么样写??
        }
    }
}很急,谢谢了!

解决方案 »

  1.   

    var temp = new MyObject.InnerObj1;
    alert(temp.name);
      

  2.   

    MyObject = {
        InnerObj1 : function() {
            this.name = "HelloWorld";
        },     InnerObj2 : function() {
            this.accessObj1 = function() {
                alert((new MyObject.InnerObj1).name);
            }
        }
    }var obj = new MyObject.InnerObj2;
    obj.accessObj1();
      

  3.   

        var MyObject = function() {
                this.name = null;
            }
            MyObject.prototype = {
                InnerObj1: function() {
                    this.name = "HelloWorld";
                },            InnerObj2: function() {                //alert(this.name)
                    this.accessObj1 = function() {//搞不懂你这个写这里是做什么
                        alert(this.name)
                    }
                    //this.accessObj1();
                }
               // ,
               // accessObj1: function() {
               //     alert(this.name)
               // }
            }
            var _MyObject = new MyObject();        _MyObject.InnerObj1();
            _MyObject.InnerObj2();
            _MyObject.accessObj
      

  4.   

    var MyObject = function() {
      this.name = null;
      }
      MyObject.prototype = {
      InnerObj1: function() {
      this.name = "HelloWorld";
      },  InnerObj2: function() {  //alert(this.name)
      this.accessObj1 = function() {//搞不懂你这个写这里是做什么
      alert(this.name)
      }
      //this.accessObj1();
      }
      // ,
      // accessObj1: function() {
      // alert(this.name)
      // }
      }
      var _MyObject = new MyObject();  _MyObject.InnerObj1();
      _MyObject.InnerObj2();
      //_MyObject.accessObj();