3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

Remove object prototype extensions in master [#135]

This commit is contained in:
reality 2013-02-12 18:34:36 +00:00
parent 77138d922e
commit c79c595ee7
3 changed files with 2 additions and 66 deletions

View File

@ -86,7 +86,7 @@ var commands = function(dbot) {
event.reply(dbot.t('search_results', {
'category': haystack,
'needle': needle,
'quote': matches.random(),
'quote': matches[0],
'matches': matches.length
}));
}

2
run.js
View File

@ -113,7 +113,7 @@ DBot.prototype.save = function() {
// Hot-reload module files.
DBot.prototype.reloadModules = function() {
if(this.modules) { // Run 'onDestroy' code for each module if it exists.
this.modules.each(function(module) {
_.each(this.modules, function(module) {
if(module.onDestroy) {
module.onDestroy();
}

View File

@ -1,9 +1,5 @@
/*** Array ***/
Array.prototype.random = function() {
return this[Math.floor((Math.random()*this.length))];
};
Array.prototype.each = function(fun) {
for(var i=0;i<this.length;i++) {
fun(this[i]);
@ -81,66 +77,6 @@ String.prototype.format = function() { // format takes either multiple indexed a
return targetStr;
};
/*** Object ***/
Object.prototype.isFunction = function(obj) {
return typeof(obj) === 'function';
};
Object.prototype.isArray = function(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
Object.prototype.isString = function(obj) {
return Object.prototype.toString.call(obj) === '[object String]';
};
Object.prototype.withAll = function(fun) {
for(key in this) {
if(this.hasOwnProperty(key)){
fun(key, this[key]);
}
}
};
Object.prototype.length = function() {
var l = 0;
for(key in this)
if(this.hasOwnProperty(key))
l++;
return l;
};
Object.prototype.sort = function(object, scorer) {
var sortArr = [];
for(var key in object) {
if(object.hasOwnProperty(key)) {
sortArr.push([key, scorer(key, object)]);
}
}
return sortArr.sort(function(a, b) { return a[1] - b[1]; });
};
Object.prototype.filter = function(fun) {
var filtered = [];
for(var key in this) {
if(this.hasOwnProperty(key)) {
if(fun(this[key]) == true) {
filtered.push(this[key]);
}
}
}
return filtered;
};
Object.prototype.each = function(fun) {
for(var key in this) {
if(this.hasOwnProperty(key)) {
fun(this[key]);
}
}
};
/*** Integer ***/
Number.prototype.chanceIn = function(x, y) {