Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. function testArguments () // <-- notice no arguments specified
  2. {
  3. console.log(arguments); // outputs the arguments to the console
  4. var htmlOutput = "";
  5. for (var i=0; i < arguments.length; i++) {
  6. htmlOutput += '<li>' + arguments[i] + '</li>';
  7. }
  8. document.write('<ul>' + htmlOutput + '</ul>');
  9. }
  10.  
  11. testArguments("This", "is", "a", "test"); // outputs ["This","is","a","test"]
  12. testArguments(1,2,3,4,5,6,7,8,9); // outputs [1,2,3,4,5,6,7,8,9]
  13.  
  14. argumentsArray = [].slice.apply(arguments);
  15.  
  16. function ArgumentsToArray(args) {
  17. return [].slice.apply(args);
  18. }
  19.  
  20. (function() {
  21. args = ArgumentsToArray(arguments);
  22.  
  23. args.forEach(function(value) {
  24. console.log('value ===', value);
  25. });
  26.  
  27. })('name', 1, {}, 'two', 3)
  28.  
  29. function foo()
  30. {
  31. foo.bar = JSON.stringify(arguments);
  32. foo.baz = JSON.parse(foo.bar);
  33. }
  34.  
  35. /* Atomic Data */
  36. foo(1,2,3,4,5,6,7);
  37. foo.bar // "{"0":1,"1":2,"2":3,"3":4,"4":5,"5":6,"6":7}"
  38. foo.baz // [object Object]
  39.  
  40. /* Structured Data */
  41. foo({1:2},[3,4],/5,6/,Date())
  42. foo.bar //"{"0":{"1":2},"1":[3,4],"2":{},"3":"Tue Dec 17 2013 16:25:44 GMT-0800 (Pacific Standard Time)"}"
  43. foo.baz // [object Object]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement