Skip to content

Instantly share code, notes, and snippets.

@ejholmes
Created May 30, 2012 02:52
Show Gist options
  • Save ejholmes/2833347 to your computer and use it in GitHub Desktop.
Save ejholmes/2833347 to your computer and use it in GitHub Desktop.
From e8ec3b84ab4eec55f2b1fe9a5cee294a5352ee78 Mon Sep 17 00:00:00 2001
From: "Eric J. Holmes" <[email protected]>
Date: Tue, 29 May 2012 19:50:13 -0700
Subject: [PATCH] Need to check if the object has it's own property, so that
libraries like emberjs don't cause issues by polluting
object prototypes.
---
js/src/utils/jwplayer.utils.strings.js | 42 +++++++++++++++++---------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/js/src/utils/jwplayer.utils.strings.js b/js/src/utils/jwplayer.utils.strings.js
index 31f5f29..5bb7499 100644
--- a/js/src/utils/jwplayer.utils.strings.js
+++ b/js/src/utils/jwplayer.utils.strings.js
@@ -122,27 +122,29 @@
isArray = (obj && obj.constructor == Array);
for (var item in obj) {
- var value = obj[item];
-
- switch (typeof(value)) {
- case "string":
- value = '"' + value.replace(/"/g, '\\"') + '"';
- break;
- case "object":
- if (jwplayer.utils.exists(value)) {
- value = jwplayer.utils.strings.jsonToString(value);
- }
- break;
- }
- if (isArray) {
- // Array
- if (typeof(value) != "function") {
- toReturn.push(String(value));
+ if (obj.hasOwnProperty(item)) {
+ var value = obj[item];
+
+ switch (typeof(value)) {
+ case "string":
+ value = '"' + value.replace(/"/g, '\\"') + '"';
+ break;
+ case "object":
+ if (jwplayer.utils.exists(value)) {
+ value = jwplayer.utils.strings.jsonToString(value);
+ }
+ break;
}
- } else {
- // Object
- if (typeof(value) != "function") {
- toReturn.push('"' + item + '":' + String(value));
+ if (isArray) {
+ // Array
+ if (typeof(value) != "function") {
+ toReturn.push(String(value));
+ }
+ } else {
+ // Object
+ if (typeof(value) != "function") {
+ toReturn.push('"' + item + '":' + String(value));
+ }
}
}
}
--
1.7.9.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment