Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2012
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)();​​​
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement