87,993
社区成员
发帖
与我相关
我的任务
分享
SEO,SEO。。
//队伍
function Ranks() {
this.persons = [];
}
Ranks.prototype.min = 3
Ranks.prototype.max = 5;
Ranks.prototype.isValid = function () { return this.persons.length >= this.min && this.persons.length <= this.max }
Ranks.prototype.add = function (p) { this.persons.push(p); if (this.persons.length > this.max) alert('超员,最大' + this.max + '人') }
//人物
function Person(name, level) {
this.name = name;
this.level = level;
}
var r = new Ranks();
r.add(new Person('p1', 1));
alert(r.isValid())
r.add(new Person('p2', 2));
r.add(new Person('p3', 3));
alert(r.isValid())
r.add(new Person('p4', 4));
r.add(new Person('p5', 5));
r.add(new Person('p6', 6));//ERROR var RanksArry = [], PeopleObj_1 = {}, PeopleObj_2 = {};
PeopleObj_1['name'] = '李四';
PeopleObj_1['age'] = '34';
PeopleObj_2['name'] = '张3';
PeopleObj_2['age'] = '35';
RanksArry.push(PeopleObj_1);
RanksArry.push(PeopleObj_2);
var peoNu = RanksArry.length;