Skip to content

Commit

Permalink
Address potential issue with Object.defineProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
steveWang committed Oct 16, 2011
1 parent bfd5157 commit 57c00b8
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions lib/nowUtil.js
Expand Up @@ -3,21 +3,6 @@
* in NowJS.
*/

Object.defineProperty(Array.prototype,
'toJSON',
{ enumerable: false,
value: function () {
if (Array.isArray(this)) {
return this;
}
var toReturn = [];
for (var i = 0, ll = this.length; i < ll; i++) {
toReturn[i] = this[i];
}
return toReturn;
}
});

var util = {
parseCookie: function (cookie) {
if (typeof cookie !== 'string') {
Expand Down Expand Up @@ -161,4 +146,20 @@ var util = {
}
};

if (!util.hasProperty(Array.prototype, 'toJSON')) {
var obj = { enumerable: false,
value: function () {
if (Array.isArray(this)) {
return this;
}
var toReturn = [];
for (var i = 0, ll = this.length; i < ll; i++) {
toReturn[i] = this[i];
}
return toReturn;
}
};
Object.defineProperty(Array.prototype, 'toJSON', obj);
}

exports.nowUtil = util;

0 comments on commit 57c00b8

Please sign in to comment.