日期:2014-05-16  浏览次数:20343 次

如何取得新建对象的引用变量名本身
我也不知道该怎么描述....看代码吧
function   testObj(name){
this.name=name;
this.show=function(){
alert(this.name);
}
}

var   test1=new   testObj( "test1name ");
test1.show();
var   test2=new   testObj( "test2name ");
test2.show();

我希望在show方法里取得 "test1 "、 "test2 "这两个字符串本身
当然var   test1=new   testObj( "test1 ")就可以的,但是,如果不这样传递参数,能取得到吗?

------解决方案--------------------
function testObj(name){ --> function testObj(){

var test1=new testObj();
test1.name= "test1name ";
test1.show();
var test2=new testObj();
test2.name= "test2name ";
test2.show();
------解决方案--------------------
不行,要传。
------解决方案--------------------
function testObj(name){
this.name=name;
this.show=function(){
alert(this.name.match(/^test\d+/i));
}
}

var test1=new testObj( "test1name ");
test1.show();
var test2=new testObj( "test2name ");
test2.show();

还是不大清楚你想干什么 试试这个
------解决方案--------------------
要传
------解决方案--------------------
......只能传
------解决方案--------------------
<a href= "javascript:void(0);onclick=new_function(this) "> 调用对象层的method方法 </a>

function new_function(o){
eval(o.id).method();
}
------解决方案--------------------
帮LZ顶

http://user.qzone.qq.com/31767702
------解决方案--------------------
晕了, 记得前段时间不是有人问题, 这是不行滴...