avoid overwriting javascript Array.prototype.map, oops

This commit is contained in:
Emi Matchu 2012-03-06 22:18:36 -05:00
parent 644fac99da
commit 7ec75bb139
2 changed files with 7 additions and 6 deletions

View file

@ -356,21 +356,21 @@ View.Hash = function (wardrobe) {
}
singleOutfitResponse('updateClosetItems', function (items) {
var item_ids = items.map('id');
var item_ids = items.mapProperty('id');
if(!arraysMatch(item_ids, data.closet)) {
changeQuery({closet: item_ids});
}
});
singleOutfitResponse('updateWornItems', function (items) {
var item_ids = items.map('id'), changes = {};
var item_ids = items.mapProperty('id'), changes = {};
if(!arraysMatch(item_ids, data.objects)) {
changes.objects = item_ids;
}
if(arraysMatch(item_ids, data.closet) || arraysMatch(item_ids, data.objects)) {
changes.closet = undefined;
} else {
changes.closet = wardrobe.outfit.getClosetItems().map('id');
changes.closet = wardrobe.outfit.getClosetItems().mapProperty('id');
}
if(changes.objects || changes.closet) changeQuery(changes);
});

View file

@ -28,7 +28,7 @@ function arraysMatch(array1, array2) {
return true;
}
Array.prototype.map = function (property) {
Array.prototype.mapProperty = function (property) {
return $.map(this, function (element) {
return element[property];
});
@ -327,11 +327,11 @@ function Wardrobe() {
new_items = [], new_worn_item_ids = [];
if(added_item) {
// now that we've loaded, check for conflicts on the added item
item_zones = added_item.getAssetsFitting(outfit.pet_type).map('zone_id');
item_zones = added_item.getAssetsFitting(outfit.pet_type).mapProperty('zone_id');
item_zones_length = item_zones.length;
for(var i = 0; i < outfit.worn_items.length; i++) {
existing_item = outfit.worn_items[i];
existing_item_zones = existing_item.getAssetsFitting(outfit.pet_type).map('zone_id');
existing_item_zones = existing_item.getAssetsFitting(outfit.pet_type).mapProperty('zone_id');
passed = true;
if(existing_item != added_item) {
for(var j = 0; j < item_zones_length; j++) {
@ -1307,6 +1307,7 @@ Wardrobe.getStandardView = function (options) {
assets.sort(function (a, b) {
return a.depth - b.depth;
});
console.log(assets.mapProperty('id'));return;
for(var i = 0; i < assets.length; i++) {
url += "," + encodeURIComponent(assets[i].imageURL(size));