js prototype问题!!!!
function test()
{
.......
}
test.prototype.hh=function(){......}
问题是 'test.prototype.hh "中的hh是一个变量的时候该怎么写??
------解决方案--------------------var variable = "变量值 ";
test.prototype.hh = variable;
------解决方案--------------------var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
var test = Class.create();
test.prototype = {
initialize: function() {
this.aa = 11;
},
hh: function() {
}
}
------解决方案--------------------function ClassA(){}
ClassA.prototype.color = "red ";
ClassA.prototype.show = function(){alert(this.color);};
------解决方案--------------------test.prototype.hh = xxx;
------解决方案--------------------function ClassA(col){
this.color = col;
}
ClassA.prototype.show = function(){alert(this.color);};
------解决方案--------------------eval( "test.prototype. "+hh+ "=function(){......} ");