acha-framework
Version:
is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...
44 lines • 1.06 kB
JavaScript
(function (window, undefined) {
'use strict';
Array.prototype.copy = function () {
return this.concat([]);
};
Array.prototype.addRange = function (array) {
var self = this;
(array || []).forEach(function (item) {
self.push(item);
});
};
Array.prototype.add = function (item, bottom) {
var index = this.indexOf(item);
if (index !== -1)
return index;
if (bottom === false) {
this.unshift(item);
return 0;
}
this.push(item);
return this.length - 1;
};
Array.prototype.del = function (item) {
var index = this.indexOf(item);
if (index !== -1) {
this.splice(index, 1);
}
return index;
};
Array.prototype.partition = function (length) {
var result = [];
for (var i = 0; i < this.length; i++) {
if (i % length === 0)
result.push([]);
result[result.length - 1].push(this[i]);
}
return result;
};
Array.prototype.pluck = function (field) {
return this.map(function (item) {
return item[field];
});
};
}(window));