var col = Column.prototype;
问题就在这个地方
改成这样
<html>
<head>
<script type= "text/javascript">
function Column(cId,cName,cDesc) {
var col = Column.prototype;
this.cId = cId;
this.cName = cName;
this.cDesc = cDesc;
col.getCId = function () {
return this.cId;
}
col.getCName = function () {
return this.cName;
}
col.getCDesc = function () {
return this.cDesc;
}
}
var obj1 = new Column(1,'1','1');
var obj2 = new Column(2,'2','2');
alert(obj1.cId);
</script>
</head>
<body>
</body>
</html>
就ok了prototype.property是所有对象实例共享的东西,所以会覆盖
问题就在这个地方
改成这样
<html>
<head>
<script type= "text/javascript">
function Column(cId,cName,cDesc) {
var col = Column.prototype;
this.cId = cId;
this.cName = cName;
this.cDesc = cDesc;
col.getCId = function () {
return this.cId;
}
col.getCName = function () {
return this.cName;
}
col.getCDesc = function () {
return this.cDesc;
}
}
var obj1 = new Column(1,'1','1');
var obj2 = new Column(2,'2','2');
alert(obj1.cId);
</script>
</head>
<body>
</body>
</html>
就ok了prototype.property是所有对象实例共享的东西,所以会覆盖
var Class = function (a) {
Class.prototype.s = function () {
alert(a);
};
};var a = new Class(1);
var b = new Class(2);
a.s();
</script>解决方法1
<script type="text/javascript">
var Class = function (a) {
this.s = function () {
alert(a);
};
};var a = new Class(1);
var b = new Class(2);
a.s();
</script>
以下省略^^