Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 2nd, 2012  |  syntax: JavaScript  |  size: 0.39 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  
  3. Best JavaScript quiz I have created so far :-)
  4.  
  5. */
  6.  
  7. var someObject = {
  8.     foo: function() {
  9.         /* ... */
  10.     },
  11.     bar: function() {
  12.         /* ... */
  13.     }        
  14. };
  15.  
  16. var test = Math.random() > 0.5;
  17.  
  18. /*
  19.  
  20. Question: What is the difference between the following calls?
  21.  
  22. */
  23.  
  24. someObject[test ? "foo" : "bar"]();  
  25. (test ? someObject.foo : someObject.bar)();​​​