I was just going through the code of Jbox and cam across the following snippet of code:
// Internal functions, used to easily get values
this._getOpp = func
It creates an object with values first, then return a specific attr in the object whose key is the given opp. And if no such key is founded, undefined is returned.
You can see them as :
var states= {
left: 'right',
right: 'left',
top: 'bottom',
bottom: 'top',
x: 'y',
y: 'x'
};
return settings[opp];
The snippet shows how it would act.
var getOpp = function(opp) {
return {left: 'right',
right: 'left',
top: 'bottom',
bottom: 'top',
x: 'y',
y: 'x'}[opp];
};
console.log(getOpp('right'));
console.log(getOpp('oops'));