HTDW_eventImplemented 函数里的 this 是直接指向 HTDW_DataWindowClass 这个类本身的.
而上面的那个 this[] 由于代码不全, 不能判断它具体指向, 可能是用户自定义类, 可能是window

解决方案 »

  1.   

    to 梅花雪,我把原码贴上来帮我看看。
    // auto binding of events expect <controlName>_<eventName>
    function HTDW_eventImplemented(sEventName)
    {
        // check if we already have one scripted
        if (this[sEventName] == null)
            {
            // check for function with default name
            var testName = this.name + '_' + sEventName;
            if (eval ('typeof ' + testName) == 'function')
                this[sEventName] = eval(testName);
            }    return this[sEventName] != null;
    }
    function HTDW_DataWindowClass(name, submitForm, actionField, contextField)
    {
        // if used in 4GL web, these will not be defined!
        if (arguments.length == 1)
            {
            submitForm = null;
            actionField = null;
            contextField = null;
            }
            
        this.name = name;
        this.submitForm = submitForm;
        this.actionField = actionField;
        this.contextField = contextField;
        this.sortString = null;
        this.action = "";
        
        // private functions
        this.buttonPress = HTDW_buttonPress;
    this.performAction = HTDW_performAction;    this.eventImplemented = HTDW_eventImplemented;
        this.itemClicked = HTDW_itemClicked;
    }
      

  2.   

    举个简单的例子来说明一下吧:
    <SCRIPT LANGUAGE="JavaScript">
    function mm(str)
    {
      this.name = str;
      this.a    = "aaa";
      this["b"] = "bbb"; //这句与上面一句代码是等效的, 都是指定 mm 类的某个属性值
    }
    var m = new mm("meizz");
    alert("m.name = "+ m.name);
    alert("m.a = "+ m.a);
    alert("m.b = "+ m.b);
    </SCRIPT>
      

  3.   

    也就是说this["b"]与this.b等价?
      

  4.   

    不过其中还是稍有点不同:
    function mm(str)
    {
      this.a    = "aaa";
      var str   = "b";
      this[str] = "bbb";  //这里的属性名称可以用一个变量的值来代替了
    }
      

  5.   

    var testName = this.name + '_' + sEventName;
            if (eval ('typeof ' + testName) == 'function')
                this[sEventName] = eval(testName);
            }
    eval ('typeof ' + testName) == 'function'这一句是判断this.name_sEventName是不是一个函数。
    this.[sEventName]=eval(testName)这一句意思是如果testName是一个函数就把它指定给this[sEventName]吗
      

  6.   

    <SCRIPT LANGUAGE="JavaScript">
    function gouzi(str)
    {
      alert("传进来的字符串是 = "+ str);
    }
    function mm(str)
    {
      this.name = str;
      this.a    = "aaa";
      var str   = "b";
      this[str] = "bbb";
      if(eval("typeof "+ "gouzi")=="function") //判断 gouzi 是否为一函数
      this.func = eval("gouzi"); //this.func 是一个方法, 具体定义就是函数 gouzi
    }
    var m = new mm("meizz");
    //alert("m.name = "+ m.name);
    //alert("m.a = "+ m.a);
    //alert("m.b = "+ m.b);
    m.func("gooooooooooouzi");
    </SCRIPT>