Skip to content

Commit

Permalink
Adding a small example that explains deep-copy of option values (a lo…
Browse files Browse the repository at this point in the history
…t of questions arise from that)
  • Loading branch information
cpojer committed Feb 23, 2011
1 parent f9f8087 commit 26459bc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Docs/Class/Class.Extras.md
Expand Up @@ -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:

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 26459bc

Please sign in to comment.