From 43d7836c8ec9b31a02a31ae0c400bdae04d3650d Mon Sep 17 00:00:00 2001 From: Douglas Crockford Date: Mon, 8 Oct 2012 14:40:29 -0700 Subject: [PATCH] Defense against window.prototype --- json.js | 5 ++--- json2.js | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) mode change 100755 => 100644 json.js diff --git a/json.js b/json.js old mode 100755 new mode 100644 index 1c2b253..9a338bf --- a/json.js +++ b/json.js @@ -1,6 +1,6 @@ /* json.js - 2011-08-30 + 2012-10-08 Public Domain @@ -196,8 +196,7 @@ // Create a JSON object only if one does not already exist. We create the // methods in a closure to avoid creating global variables. -var JSON; -if (!JSON) { +if (typeof JSON !== 'object') { JSON = {}; } diff --git a/json2.js b/json2.js index 3b0c872..c7745df 100644 --- a/json2.js +++ b/json2.js @@ -1,6 +1,6 @@ /* json2.js - 2011-10-19 + 2012-10-08 Public Domain. @@ -159,8 +159,7 @@ // Create a JSON object only if one does not already exist. We create the // methods in a closure to avoid creating global variables. -var JSON; -if (!JSON) { +if (typeof JSON !== 'object') { JSON = {}; }