Interesting behaviour when passing objects in as options to a widget
I've just come across an odd affect in a widget I'm coding up. I've worked around it, but would be grateful if anyone has a better approach / can explain why this is (or should be) occuring.
Basically, I'm passing a self referencing object into the options property of the widget:
e.g.
var obj1 = {Name: 'child' ...etc}
var obj2 = {Name: 'parent', child: obj1, childArray: [obj1] ...etc }
$(
"#flowTreeDraggableBackground"
).flowTree( { flowableObjectTree: obj2 } );
The problem I have is that obj2.child is no longer the same as obj2.childArray[0]
I'm kind of assuming that when options are passed into a widget they are cloned..
Is this right?
I've worked around the case by exposing a public method to set the property, and saving this into the .data store within the plugin - so it's initialised something like this:
$(
"#flowViewDraggableBackground"
).flowTree().flowTree(
'setSourceData'
, obj2).flowTree(
'render'
);
Do you think this is the best approach?