Hey guys , I kind of have a really weird question , recently i was just going through a small piece of code on Github and came across the following snippet :
- // Internal functions, used to easily get values
- this._getOpp = function(opp) {
- return {left: 'right',
- right: 'left',
- top: 'bottom',
- bottom: 'top',
- x: 'y',
- y: 'x'}[opp];
- };
it turns out , the above syntax is similar to switch case and is good for declaring internal methods in a plugin. (i got to know this on SO) .
now i came across this syntax , not while coding , but while just reading through a library code(and trying to possible make some sense of the code). So basically i was't coding or writing code myself , i was just glancing through someone else's code and i ended up learning something new.
coding is certainly the best way to learning , but is also checking out stuff(not coding .. just glancing through code or debugging a snippet already coded ) also a great way to learn JS(or any programming language for that matter ) ? i know its a bit of a stupid question , but i just taught i would ask . Has it every occurred to you too that , you've learned something new , by just looking at how someone has coded a certain snippet or library ?
Thank you