Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…t of questions arise from that)
  • Loading branch information...
commit 26459bcc0e1f9471fd83083484ba46d326e65be3 1 parent f9f8087
@cpojer cpojer authored
Showing with 13 additions and 1 deletion.
  1. +13 −1 Docs/Class/Class.Extras.md
View
14 Docs/Class/Class.Extras.md
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.