Skip to content

Instantly share code, notes, and snippets.

@st98
Last active August 29, 2015 14:00
Show Gist options
  • Save st98/11324352 to your computer and use it in GitHub Desktop.
Save st98/11324352 to your computer and use it in GitHub Desktop.
Array#toString を少し見やすく。ただしコードは醜い。
Object.defineProperty(Array.prototype, 'toString', {
value: (function () {
var start = '[';
var end = ']';
var delimiter = ', '
function toString() {
var index = 0;
var len = this.length;
var result = '';
result += start;
for (; index < len; index++) {
result += this[index];
if (index < len - 1) {
result += delimiter;
}
}
result += end;
return result;
};
return toString;
})(),
writable: true,
enumerable: false,
configurable: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment