CType = function(Text)
{this.nType = GetType(Text);}CType.GetType = function(Text)
{/* ... */}// ...Type = new CType(Str);
好像arguments.callee.GetType可以?能不能直接写GetType?

解决方案 »

  1.   

    arguments.callee.GetType是可以
    直接写不可以吧
    总得找一个对这个函数的引用吧
      

  2.   


    CType = function(Text)
        {this.nType = CType.GetType(Text);}CType.GetType = function(Text)
        {/* ... */}// ...Type = new CType(Str);
      

  3.   

    To TinyJimmy:我事先并不能确定这个函数叫CType,所以不能这么用。另外追加一点,如果在这个函数的方法中,又如何使用这个函数的属性?
    this.prototype.constructor.GetType?
      

  4.   

    我想问 一下
    CType = function(Text)
        {this.nType = GetType(Text);}Ctype是定义在全局里面的吧那在这个函数的作用域下还能找到它???????
      

  5.   

    this.prototype.constructor.GetType
    这么写应该不行吧
    this是指向调用该函数的对象
    很可能就不是指向CType 的
    CType.prototype.constructor.GetType可以
    但是this.prototype.constructor.GetType
    是不行的吧  
    同你说的 CType不确定   用arguments.callee算了
      

  6.   


    CType肯定是和函数同一个作用域的,所以函数内部能够使用CType。
    但是我想随时随地更改CType这个名字,所以函数里面最好不要用它,否则一改就全都要改了。
      

  7.   


    这问题大了……
    在那个匿名函数的方法里,arguments.callee应该是指代这个方法本身,而不是匿名函数。
    这个方法的prototype.constructor指代的又是什么?
    晕了……
      

  8.   

    函数原形下的constructor引用的是函数本身可以测试一下
    CType = function(Text){
    this.nType = GetType(Text);
    alert(1);
    alert(2)
    }
    function GetType(Text){/* ... */}
    CType.prototype.constructor();
    你这个是什么意思 看不懂
    在那个匿名函数的方法里,arguments.callee应该是指代这个方法本身,而不是匿名函数你能写个例子吗??//?
      

  9.   

    <html>
    <body><script type="text/javascript">CType = function(Text)
        {
        this.nType0 = CType.GetType(Text);
        this.nType1 = arguments.callee.GetType(Text);
        this.nType2 = this.prototype.constructor.GetType(Text);
        this.nType3 = GetType(Text);    this.MyGetType0 = function(Text) {return CType.GetType(Text);}
        this.MyGetType1 = function(Text) {return arguments.callee.GetType(Text);}
        this.MyGetType2 = function(Text) {return this.prototype.constructor.GetType(Text);}
        this.MyGetType3 = function(Text) {return GetType(Text);}
        }CType.GetType = function(Text)
        {return Text;}// ...Type = new CType("Hello");alert("Type.nType0: " + Type.nType0);
    alert("Type.nType1: " + Type.nType1);
    alert("Type.nType2: " + Type.nType2);
    alert("Type.nType3: " + Type.nType3);
    alert("Type.MyGetType0(): " + Type.MyGetType0("World"));
    alert("Type.MyGetType1(): " + Type.MyGetType1("World"));
    alert("Type.MyGetType2(): " + Type.MyGetType2("World"));
    alert("Type.MyGetType3(): " + Type.MyGetType3("World"));</script></body>
    </html>
    正在挨个测试
      

  10.   

    <html><body><script type="text/javascript">CType = function(Text)
    {
    // this.nType = CType.GetType(Text);
    // this.nType = arguments.callee.GetType(Text);
    //! this.nType = this.prototype.constructor.GetType(Text);
    this.nType = this.constructor.GetType(Text);
    //! this.nType = GetType(Text);// this.MyGetType = function(Text) {return CType.GetType(Text);}
    //! this.MyGetType = function(Text) {return arguments.callee.GetType(Text);}
    //! this.MyGetType = function(Text) {return this.prototype.constructor.GetType(Text);}
    this.MyGetType = function(Text) {return this.constructor.GetType(Text);}
    //! this.MyGetType = function(Text) {return GetType(Text);}
    }CType.GetType = function(Text) {return Text;}// ...Type = new CType("OK");document.write("Type.nType: " + Type.nType + "<br />");
    document.write("Type.MyGetType(): " + Type.MyGetType("OK") + "<br />");</script></body></html>上面注释形式是"//!"的表示调用不成功。令我惊奇的是,在MyGetType方法里,this.prototype为未定义(不过arguments.callee.prototype倒是存在)。
      

  11.   

    上面那个问题弄明白了,this指代的是Type这个对象,它不是函数,所以没有prototype属性。
      

  12.   

      哥们:看你都提了几个javascript 面向对象的问题了。我要告诉你的是。千万不要用别的面向对象的语言来来理解javascript的面向对象。 比如说继承, this... 这些东西。 如果你那样做了。马上改过来吧。 不然你无法真正理解javascript 。javascript 是非常灵活,松散的动态语言。并不像别的非动态语言的方式来实现面向对象的编程。比如继承: 实际上javascript并不支持继承,只能说是模拟继承。看看这个帖子吧: http://topic.csdn.net/u/20100225/11/4c2cd54f-6347-4c04-b8d3-25a4d169bb0b.html 希望对你有所帮助。
      

  13.   

    用prototype呢?
    CType = function(Text)
        {this.nType = this.GetType(Text);}CType.prototype.GetType = function(Text)
        {return Text + "1";}Type = new CType("abc");
    alert(Type.nType);