I have a number of files with contents like this:
function hello() {
...
element1.text = foo.locale.lorem;
element2.text = foo.locale.ipsum;
...
elementn.text = foo.locale.whatever;
...
}
function world() {
...
var label = bar.options.baz.blah;
var toggle = bar.options.baz.use_toggle;
...
}
This could be written more efficiently, and also be more readable, by creating a shortcut to the locale object:
function hello() {
var loc = foo.locale;
...
element1.text = loc.lorem;
element2.text = loc.ipsum;
...
elementn.text = loc.whatever;
...
}
function world() {
var options = bar.options.baz;
...
var label = options.blah;
var toggle = options.use_toggle;
...
}
Is there a simple way to detect occurrences of such duplication for any arbitrary object (it's not always as simple as "locale", or foo.something
)?
Basically, I wanna know where lengthy object references appear two or more times within a function.
Thanks!