在匿名函数中,如何使用该函数的属性? CType = function(Text) {this.nType = GetType(Text);}CType.GetType = function(Text) {/* ... */}// ...Type = new CType(Str);好像arguments.callee.GetType可以?能不能直接写GetType? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 arguments.callee.GetType是可以直接写不可以吧总得找一个对这个函数的引用吧 CType = function(Text) {this.nType = CType.GetType(Text);}CType.GetType = function(Text) {/* ... */}// ...Type = new CType(Str); To TinyJimmy:我事先并不能确定这个函数叫CType,所以不能这么用。另外追加一点,如果在这个函数的方法中,又如何使用这个函数的属性?this.prototype.constructor.GetType? 我想问 一下CType = function(Text) {this.nType = GetType(Text);}Ctype是定义在全局里面的吧那在这个函数的作用域下还能找到它??????? this.prototype.constructor.GetType这么写应该不行吧this是指向调用该函数的对象很可能就不是指向CType 的CType.prototype.constructor.GetType可以但是this.prototype.constructor.GetType是不行的吧 同你说的 CType不确定 用arguments.callee算了 CType肯定是和函数同一个作用域的,所以函数内部能够使用CType。但是我想随时随地更改CType这个名字,所以函数里面最好不要用它,否则一改就全都要改了。 这问题大了……在那个匿名函数的方法里,arguments.callee应该是指代这个方法本身,而不是匿名函数。这个方法的prototype.constructor指代的又是什么?晕了…… 函数原形下的constructor引用的是函数本身可以测试一下CType = function(Text){ this.nType = GetType(Text); alert(1); alert(2)}function GetType(Text){/* ... */}CType.prototype.constructor();你这个是什么意思 看不懂在那个匿名函数的方法里,arguments.callee应该是指代这个方法本身,而不是匿名函数你能写个例子吗??//? <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>正在挨个测试 <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倒是存在)。 上面那个问题弄明白了,this指代的是Type这个对象,它不是函数,所以没有prototype属性。 哥们:看你都提了几个javascript 面向对象的问题了。我要告诉你的是。千万不要用别的面向对象的语言来来理解javascript的面向对象。 比如说继承, this... 这些东西。 如果你那样做了。马上改过来吧。 不然你无法真正理解javascript 。javascript 是非常灵活,松散的动态语言。并不像别的非动态语言的方式来实现面向对象的编程。比如继承: 实际上javascript并不支持继承,只能说是模拟继承。看看这个帖子吧: http://topic.csdn.net/u/20100225/11/4c2cd54f-6347-4c04-b8d3-25a4d169bb0b.html 希望对你有所帮助。 用prototype呢?CType = function(Text) {this.nType = this.GetType(Text);}CType.prototype.GetType = function(Text) {return Text + "1";}Type = new CType("abc");alert(Type.nType); 求代码? ajax跨子域名的问题 Javascript 中radiobuttonlist赋值问题 救我,我快疯了 正则表达式,怎么取一段html 如何让一个输入框中只能输入数字? 在php中获取js克隆表的数据 这段代码改成c可以运行,可在网页里运行,就停不了了,郁闷啊。。。。。。。。。。 VBScript调用JavaScript,参数有两个就不行了!救救急! 急救:请问在JS中怎样实现下面的功能? Ext中tabpanel中加入一个tab同时tab中包含一个grid 大师的书就是不容易看懂啊
直接写不可以吧
总得找一个对这个函数的引用吧
CType = function(Text)
{this.nType = CType.GetType(Text);}CType.GetType = function(Text)
{/* ... */}// ...Type = new CType(Str);
this.prototype.constructor.GetType?
CType = function(Text)
{this.nType = GetType(Text);}Ctype是定义在全局里面的吧那在这个函数的作用域下还能找到它???????
这么写应该不行吧
this是指向调用该函数的对象
很可能就不是指向CType 的
CType.prototype.constructor.GetType可以
但是this.prototype.constructor.GetType
是不行的吧
同你说的 CType不确定 用arguments.callee算了
CType肯定是和函数同一个作用域的,所以函数内部能够使用CType。
但是我想随时随地更改CType这个名字,所以函数里面最好不要用它,否则一改就全都要改了。
这问题大了……
在那个匿名函数的方法里,arguments.callee应该是指代这个方法本身,而不是匿名函数。
这个方法的prototype.constructor指代的又是什么?
晕了……
CType = function(Text){
this.nType = GetType(Text);
alert(1);
alert(2)
}
function GetType(Text){/* ... */}
CType.prototype.constructor();
你这个是什么意思 看不懂
在那个匿名函数的方法里,arguments.callee应该是指代这个方法本身,而不是匿名函数你能写个例子吗??//?
<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>
正在挨个测试
{
// 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倒是存在)。
CType = function(Text)
{this.nType = this.GetType(Text);}CType.prototype.GetType = function(Text)
{return Text + "1";}Type = new CType("abc");
alert(Type.nType);