【发布时间】:2012-10-19 10:23:45
【问题描述】:
function myClass(a,b,c) {
this.alertMyName=function(){alert(instancename)}
{...}
}
然后
foo = myClass(a,b,c);
boo = myClass(a,b,c);
foo.alertMyName(); //it should alert 'foo'
boo.alertMyName(); //it should alert 'boo'
实际上,对于创建大量 html 对象的类,我需要它来为其 ID 加上前缀,以将它们与此类的另一个实例创建的同一对象区分开来。
【问题讨论】:
-
您可以将实例名称作为参数传递或使用
this。 -
alert(this) 返回 [object Object]
标签: javascript class