尝试用面向对象的思路写js
//定义一个js对象
function EvaTemplate_IndexLinkInfo(Id, TemplateId, ElementId, IsMust, Index, Weight)
{
this.Id = Id;
this.TemplateId = TemplateId;
this.ElementId = ElementId;
this.IsMust = IsMust;
this.Index = Index;
this.Weight = Weight;
//实例方法写法一
this.equals=function(obj)
{
if (obj1.TemplateId == obj2.TemplateId
&& obj1.ElementId == obj2.ElementId
&& obj1.IsMust == obj2.IsMust
&& obj1.Index == obj2.Index
&& obj1.Weight == obj2.Weight)
return true;
return false;
}
}
//实例方法写法二
EvaTemplate_IndexLinkInfo.prototype.equals=function(obj)
{
if (obj1.TemplateId == obj2.TemplateId
&& obj1.ElementId == obj2.ElementId
&& obj1.IsMust == obj2.IsMust
&& obj1.Index == obj2.Index
&& obj1.Weight == obj2.Weight)
return true;
return false;
}
//判断两个实例是否相等的静态方法(其实是一种伪装的静态方法)
EvaTemplate_IndexLinkInfo.equals = function(obj1, obj2)
{
if (obj1.TemplateId == obj2.TemplateId
&& obj1.ElementId == obj2.ElementId
&& obj1.IsMust == obj2.IsMust
&& obj1.Index == obj2.Index
&& obj1.Weight == obj2.Weight)
return true;
return false;
}