这里有一段脚本文件 如下
(lib._02_1 = function() {
this.initialize();
this.instance = new lib.金光右_1();
this.instance.setTransform(2480.5,1090,1,1,0,0,0,2480.5,1092.5);
this.instance_1 = new lib.金光左_1();
this.instance_1.setTransform(2480.5,1090,1,1,0,0,0,2480.5,1092.5);
this.instance_2 = new lib.魔法师_1();
this.instance_2.setTransform(2480.5,1090,1,1,0,0,0,2480.5,1092.5);
this.instance_3 = new lib.宝箱();
this.instance_3.setTransform(0,-2.4);
this.instance_4 = new lib.阿拉丁_1();
this.instance_4.setTransform(2480.5,1090,1,1,0,0,0,2480.5,1092.5);
this.instance_5 = new lib.罐子2();
this.instance_5.setTransform(0,-2.4);
this.instance_6 = new lib.罐子1();
this.instance_6.setTransform(0,-2.4);
this.instance_7 = new lib.背景();
this.addChild(this.instance_7,this.instance_6,this.instance_5,this.instance_4,this.instance_3,this.instance_2,this.instance_1,this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = new cjs.Rectangle(0,-2.4,4961,2187.5);这是代码的一部分 这里的this具体指的是什么?引用的脚本里 根本没定义instance,instance_1 ... 的变量 所以小弟看着有点蒙 不知道这里的this具体指向的是什么。脚本JavaScripthtml5

解决方案 »

  1.   


    var person = function(name,age){
        this.name=name;
        this.age =age;
    }var min = new person("小明",20);
    alert(min.name);
    基础的javascript类定义啊。
      

  2.   

    JS 中 this 单从function中看不出确定是什么,要看实际怎么调用的
    这this,一般是 实例 lib._02_1 的对象
      

  3.   


    那instance 呢?主要是 我也没定义一个全局叫instance的变量啊
      

  4.   

    我现在想明确一下 this.instance 这个instance是一个未定义的变量 所以看不太懂~请多多指教
      

  5.   

     我现在想明确一下 this.instance 这个instance是一个未定义的变量 所以看不太懂~请多多指教
     this.instance = new lib.金光右_1(); 这里赋值
      

  6.   

    我现在想明确一下 this.instance 这个instance是一个未定义的变量 所以看不太懂~请多多指教
     this.instance = new lib.金光右_1(); 这里赋值
    那就是 这个instance 是一个动态创建的变量了?
      

  7.   

    是的
    十分感谢耐心回答 
    如果这样 我没办法在 这个函数之外的方法里 取到这个instance的值了吧?
      

  8.   

     var obj={};
    obj.xxx="自定义";
    alert(obj.xxx);
      

  9.   

    我现在想明确一下 this.instance 这个instance是一个未定义的变量 所以看不太懂~请多多指教
    赞成二楼~
    lib._02_1是个构造函数,this在这里应该是指lib._02_1的实例。至于instance在这儿是给this(即lib._02_1的实例)添加的一个属性的名字,并不是变量。
    比如:var obj=new lib._02_1();//实例化,在实例化过程中obj(通过this.instance=...)取得instance属性
    alert(obj.instance);//实例化后,便可以访问obj的instance属性
      

  10.   

    this.instance_1  this.instance_2 this.instance_3 this.instance_4.。。明显是个 数组的节奏
    下次这样的节奏 请直接用数组
    this.instance[0] this.instance[1] this.instance[2]
      

  11.   

    是的
    十分感谢耐心回答 
    如果这样 我没办法在 这个函数之外的方法里 取到这个instance的值了吧?

    可以的 ,比如 var obj= new lib._02_1();   obj.instance
      

  12.   


    (lib._02_1 = function() {
        this.initialize();
        this.instance = new lib.金光右_1();
    }).prototype = p = new cjs.Container();
    p.nominalBounds = new cjs.Rectangle(0,-2.4,4961,2187.5);lib._02_1 = function() {... 红色部分理解为一个类lib._02_1 = function(){} 把一个类存放到变量 lib._02_1.prototype = p = new cjs.Container();
    cjs.Container 这个类(就叫他父类吧),实例化后赋值给 p 这个变量lib._02_1.prototype = p;
    等同于
    lib._02_1.prototype = new cjs.Container();
    让 lib._02_1 这个类,继承 cjs.Container 这个类的所有方法p.nominalBounds = new cjs.Rectangle(0,-2.4,4961,2187.5);
    父类的实例化对象 p 的一个属性 nominalBounds = cjs.Rectangle 实例化后的对象
    =========================================================================
    所以,子类 lib._02_1 继承自父类 cjs.Container
    this 是子类 lib._02_1 实例化后的对象,
    this.initialize(); 调用 父类 cjs.Container.prototype.initialize = function(){} 这个方法
      

  13.   

    是的
    十分感谢耐心回答 
    如果这样 我没办法在 这个函数之外的方法里 取到这个instance的值了吧?

    可以的 ,比如 var obj= new lib._02_1();   obj.instance
    明白了 非常感谢