Skip to content

Commit

Permalink
Define extensions to core objects as writable. Fixes issue #46
Browse files Browse the repository at this point in the history
  • Loading branch information
hns committed Apr 26, 2010
1 parent 4de1db5 commit 404cc00
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions modules/core/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.shared = true;
Object.defineProperty(Array.prototype, "contains", {
value: function(val) {
return this.indexOf(val) > -1;
}
}, writable: true
});

/**
Expand All @@ -42,7 +42,7 @@ Object.defineProperty(Array.prototype, "contains", {
Object.defineProperty(Array.prototype, "peek", {
value: function() {
return this[this.length - 1];
}
}, writable: true
});

/**
Expand All @@ -59,8 +59,8 @@ Object.defineProperty(Array.prototype, "remove", {
this.splice(index, 1);
}
return this;
}
})
}, writable: true
});

/**
* Retrieve the union set of a bunch of arrays
Expand All @@ -81,7 +81,7 @@ Object.defineProperty(Array, "union", {
}
}
return result;
}
}, writable: true
});

/**
Expand All @@ -106,7 +106,7 @@ Object.defineProperty(Array, "intersection", {
result.push(item);
}
return result;
}
}, writable: true
});

/**
Expand All @@ -115,7 +115,7 @@ Object.defineProperty(Array, "intersection", {
Object.defineProperty(Array.prototype, "max", {
value: function() {
return Math.max.apply( Math, this );
}
}, writable: true
});

/**
Expand All @@ -124,7 +124,7 @@ Object.defineProperty(Array.prototype, "max", {
Object.defineProperty(Array.prototype, "min", {
value: function() {
return Math.min.apply( Math, this );
}
}, writable: true
});

Object.defineProperty(Array.prototype, "partition", {
Expand All @@ -138,6 +138,6 @@ Object.defineProperty(Array.prototype, "partition", {
}
}
return [trues, falses]
}
}, writable: true
});

16 changes: 8 additions & 8 deletions modules/core/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Object.defineProperty(Date.prototype, "format", {
if (timezone && timezone != sdf.getTimeZone())
sdf.setTimeZone(timezone);
return sdf.format(this);
}
}, writable: true
});


Expand All @@ -73,7 +73,7 @@ Object.defineProperty(Date.prototype, "format", {
Object.defineProperty(Date.prototype, "toUtc", {
value: function() {
this.setMinutes(this.getMinutes() + this.getTimezoneOffset());
}
}, writable: true
});

/**
Expand All @@ -83,7 +83,7 @@ Object.defineProperty(Date.prototype, "toUtc", {
Object.defineProperty(Date.prototype, "toLocalTime", {
value: function() {
this.setMinutes(this.getMinutes() - this.getTimezoneOffset());
}
}, writable: true
});


Expand All @@ -94,7 +94,7 @@ Object.defineProperty(Date.prototype, "toLocalTime", {
Object.defineProperty(Date.prototype, "diff", {
value: function(dateObj) {
return this.getTime() - dateObj.getTime();
}
}, writable: true
});


Expand Down Expand Up @@ -146,7 +146,7 @@ Object.defineProperty(Date.prototype, "getTimespan", {
}
result.span = res.pop();
return result;
}
}, writable: true
});


Expand All @@ -161,7 +161,7 @@ Object.defineProperty(Date.prototype, "getAge", {
if (!age.isFuture)
return age.span;
return null;
}
}, writable: true
});


Expand All @@ -176,7 +176,7 @@ Object.defineProperty(Date.prototype, "getExpiry", {
if (age.isFuture)
return age.span;
return null;
}
}, writable: true
});


Expand Down Expand Up @@ -211,6 +211,6 @@ Object.defineProperty(Date.prototype, "equals", {
return false;
}
return true;
}
}, writable: true
});

4 changes: 2 additions & 2 deletions modules/core/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Object.defineProperty(Number.prototype, 'format', {
}
var df = new java.text.DecimalFormat(fmt || "###,##0.##", symbols);
return df.format(+this);
}
}, writable: true
});

/**
Expand All @@ -32,5 +32,5 @@ Object.defineProperty(Number.prototype, 'times', {
for (var i = 0; i < this; i++) {
fun(i);
}
}
}, writable: true
});
2 changes: 1 addition & 1 deletion modules/core/regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ module.shared = true;
Object.defineProperty(RegExp, 'escape', {
value: function (str) {
return str.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&");
}
}, writable: true
});

0 comments on commit 404cc00

Please sign in to comment.