CPDictionary dictionaryWithJSObject methods

This commit is contained in:
Tom Robinson committed 2009-02-18 18:41:43 -08:00
1 parent 0fe9de4f09
commit 9890fbd57a
1 file changed
+32
+32
View File
@@ -123,6 +123,38 @@
return [[self alloc] initWithObjects:objects forKeys:keys];
}
/*!
Creates a dictionary with multiple key-value pairs.
@param JavaScript object
@return the new CPDictionary
*/
+ (id)dictionaryWithJSObject:(JSObject)object
{
return [self dictionaryWithJSObject:object recursively:NO];
}
/*!
Creates a dictionary with multiple key-value pairs, recursively.
@param JavaScript object
@return the new CPDictionary
*/
+ (id)dictionaryWithJSObject:(JSObject)object recursively:(BOOL)recursively
{
var dictionary = [[self alloc] init];
for (var key in object)
{
var value = object[key];
if (recursively && value.constructor === Object)
value = [CPDictionary dictionaryWithJSObject:value recursively:YES];
[dictionary setObject:value forKey:key];
}
return dictionary;
}
/*!
Initializes the dictionary with the contents of another dictionary.
@param aDictionary the dictionary to copy key-value pairs from