mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-20 21:49:22 +00:00
CPDictionary dictionaryWithJSObject methods
This commit is contained in:
1 parent
0fe9de4f09
commit
9890fbd57a
1 file changed
+32
@@ -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
|
||||
|
||||
Reference in new issue
Block a user