If one has a choice to design things one way or the other, is it generally better (by way of performance, maintainability, readability, functionality, etc...) to do function chaining or use object property accessors for hierarchical access, and why?
Does it depend entirely on use case, or is one generally superior?
Example:
var foo = bar.get('parent').get('child').get('grandChild')...
// vs
var foo = bar['parent']['child']['grandChild']...
// or
var foo = bar.parent.child.grandChild...
Or is there a better way to do it altogether?
Note that dot notation .
may not always be viable due to source minification, using property values that are not valid JavaScript identifiers, etc.
EDIT:
Since that's too generic, what about a more specific example...
Consider the following...
var animals = {
dogs: {
'Chloe': {
name: 'Chloe',
fetch: function() {},
rollover: function() {},
pups: {
'Charlie': {
name: 'Charlie',
fetch: function() {},
rollover: function() {}
},
'Lily': {
//...
}
}
},
'Toby': {
//...
}
},
cats: {
'Fido': {
name: 'Fido',
meow: function() {},
kittens: {
'Mia': {
name: 'Mia',
meow: function() {}
},
'Shadow': {
//...
}
}
}
}
}
Note that this is an attempt to show a heirarchy and does not show any prototypical inheritance, although it may be present (and probably would be in the example).
In the heirarchy as shown, one would use property access to get to a certain pup as follows
var myPup = animals.dogs['Chloe'].pups['Charlie'];
// or
var myPup = animals.dogs.Chloe.pups.Charlie;
// or
var myPup = animals['dogs']['Chloe']['pups']['Charlie'];
Is this ideal? Or are there significant benefits to using functions to access the pup
var myPup = animals.dogs('Chloe').pups('Charlie');