Advertisement
rudifa

Demo underscore.js v.01

Apr 4th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.37 KB | None | 0 0
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.1.7/underscore-min.js"></script>
  5.  
  6. <script type="text/javascript">
  7.  
  8. // A minimal demo of underscore.js by @rudifa
  9. // Version 0.1
  10. // Wraps example code from http://net.tutsplus.com/tutorials/javascript-ajax/getting-cozy-with-underscore-js/
  11. // in js functions and a html page
  12.  
  13. function getScores() {
  14.     var scores = [84, 99, 91, 65, 87, 55, 72, 68, 95, 42],
  15.     topScores = [], scoreLimit = 90;
  16.     // plain js
  17.     for (i=0; i<=scores.length; i++) {
  18.        if (scores[i]>scoreLimit) {
  19.             topScores.push(scores[i]);
  20.         }
  21.     }
  22.     return (topScores);
  23. };
  24.  
  25. function getScores_() {
  26.     var scores = [84, 99, 91, 65, 87, 55, 72, 68, 95, 42],
  27.     scoreLimit = 90;
  28.     // _ js
  29.     return (_.select(scores, function(score){ return score > scoreLimit; }));
  30. };
  31. </script>
  32.  
  33. <script type="text/javascript">
  34.  
  35. function display() {
  36.     document.write("Hello Underscore!<br>");
  37.     document.write(getScores() + "<br>");
  38.     document.write(getScores_() + "<br>");
  39.     console.log("Hello Underscore!");
  40.     console.log(getScores());
  41.     console.log(getScores_());
  42. }
  43. </script>
  44.  
  45. </head>
  46.  
  47. <body>
  48.  
  49. <div id="welcome"></div>
  50. <em>Underscore Demo</em>
  51. <p>
  52. <form>
  53. <input type="button" value="Click me!" onclick="display()" />
  54. </form>
  55.  
  56. </body>
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement