You only have one object to work with, so anything you changed in previous steps are "carried along" until you explicitly change them.
To work with a new dialog object each time I would recommend using a function that returns a new instance each time and hide the settings
and open
properties:
function dialog()
{
var settings = {
controller: '',
click: false,
clas: ''
},
open = function(x) {
console.log(JSON.stringify(x));
};
return {
type: {
foo: function() {
settings.controller = 'Foo controller';
settings.clas = 'Foo class';
open(settings);
},
bar: function() {
settings.click = true;
open(settings);
}
}
};
}
And then:
var a = dialog();
a.type.foo();
var b = dialog();
b.type.bar();
var c = dialog();
c.type.foo();
It avoids the issues you would otherwise face with using this
in all kinds of contexts, because settings
and open
are always within the scope of the API that you return from the dialog()
function.