/**
*@class ArrayList
*@description
*@time 2014-09-16 21:59
*@author StarZou
**/
function ArrayList(arr) {
this._elementData = arr || [];
}
var arrayListPrototype = {
'_arrayPrototype': Array.prototype,
'_getData': function () {
return this._elementData;
},
'size': function () {
return this._getData().length;
},
'isEmpty': function () {
return this.size() === 0;
},
'contains': function (obj) {
return this.indexOf(obj) > -1;
},
'indexOf': function (obj) {
var i , data = this._getData(), length = data.length;
for (i = 0; i < length; i++) {
if (obj === data[i]) {
return i;
}
}
return -1;
},
'lastIndexOf': function (obj) {
var i , data = this._getData(), length = data.length;
for (i = length - 1; i > -1; i--) {
if (obj === data[i]) {
return i;
}
}
return -1;
},
'get': function (index) {
return this._getData()[index];
},
'set': function (index, element) {
this._getData()[index] = element;
},
'add': function (index, element) {
if (element) {
this.set(index, element);
} else {
return this._getData().push(index);
}
},
'remove': function (index) {
var oldValue = this._getData()[index];
this._getData()[index] = null;
return oldValue;
},
'clear': function () {
this._getData().length = 0;
},
'addAll': function (index, array) {
if (array) {
this._getData().splice(index, 0, array);
} else {
this._arrayPrototype.push.apply(this._getData(), index);
}
}
};
ArrayList.prototype = arrayListPrototype;
// Test 代码
var arr = new ArrayList([3, 6, 5, 'xyz', 'foo', 'xyz']);
console.log(arr.contains('xyz'));
console.log(arr.indexOf('xyz'));
console.log(arr.lastIndexOf('xyz'));
console.log(arr.get(2));
arr.addAll([1, 2, 3]);
console.log(arr);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有