From b279ef6eb88d4b34622e9750225abca4927eeacd Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Tue, 4 Mar 2008 23:33:59 +0000 Subject: [PATCH] Added Util.isPlainObject(). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4952 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/StringUtil.as | 2 +- src/as/com/threerings/util/Util.as | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/as/com/threerings/util/StringUtil.as b/src/as/com/threerings/util/StringUtil.as index 174731263..6479a9176 100644 --- a/src/as/com/threerings/util/StringUtil.as +++ b/src/as/com/threerings/util/StringUtil.as @@ -229,7 +229,7 @@ public class StringUtil } return "Array(" + s + ")"; - } else if (obj.constructor == Object) { + } else if (Util.isPlainObject(obj)) { // TODO: maybe do this for any dynamic object? (would have to use describeType) s = ""; for (var prop :String in obj) { diff --git a/src/as/com/threerings/util/Util.as b/src/as/com/threerings/util/Util.as index 673270879..be71657e4 100644 --- a/src/as/com/threerings/util/Util.as +++ b/src/as/com/threerings/util/Util.as @@ -23,6 +23,8 @@ package com.threerings.util { import flash.utils.ByteArray; +import flash.utils.describeType; // function import + public class Util { /** @@ -58,6 +60,14 @@ public class Util } } + /** + * Returns true if the specified object is just a regular old associative hash. + */ + public static function isPlainObject (obj :Object) :Boolean + { + return (obj != null) && ("Object" == describeType(obj).@name.toString()); + } + /** * Is the specified object 'simple': one of the basic built-in flash types. */