Permalink
Browse files

Adding a small example that explains deep-copy of option values (a lo…

…t of questions arise from that)
  • Loading branch information...
1 parent f9f8087 commit 26459bcc0e1f9471fd83083484ba46d326e65be3 @cpojer cpojer committed Feb 23, 2011
Showing with 13 additions and 1 deletion.
  1. +13 −1 Docs/Class/Class.Extras.md
View
@@ -344,7 +344,7 @@ Will also add Class [Events][] when the option property begins with 'on' and is
Options Method: setOptions {#Options:setOptions}
------------------------------------------------
-Merges the default options of the Class with the options passed in.
+Merges the default options of the Class with the options passed in. Every value passed in to this method will be deep copied. Therefore other class instances or objects that are not intended for copying must be passed to a class in other ways.
### Syntax:
@@ -383,6 +383,18 @@ Merges the default options of the Class with the options passed in.
//myWidget.options is now: {color: #f00, size: {width: 200, height: 100}}
+ // Deep copy example
+ var mySize = {
+ width: 50,
+ height: 50
+ };
+
+ var myWidget = new Widget({
+ size: mySize
+ });
+
+ (mySize == myWidget.options.size) // false! mySize was copied in the setOptions call.
+
### Notes:
- Relies on the default options of a Class defined in its options property.

0 comments on commit 26459bc

Please sign in to comment.