Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.1.7/underscore-min.js"></script>
- <script type="text/javascript">
- // A minimal demo of underscore.js by @rudifa
- // Version 0.1
- // Wraps example code from http://net.tutsplus.com/tutorials/javascript-ajax/getting-cozy-with-underscore-js/
- // in js functions and a html page
- function getScores() {
- var scores = [84, 99, 91, 65, 87, 55, 72, 68, 95, 42],
- topScores = [], scoreLimit = 90;
- // plain js
- for (i=0; i<=scores.length; i++) {
- if (scores[i]>scoreLimit) {
- topScores.push(scores[i]);
- }
- }
- return (topScores);
- };
- function getScores_() {
- var scores = [84, 99, 91, 65, 87, 55, 72, 68, 95, 42],
- scoreLimit = 90;
- // _ js
- return (_.select(scores, function(score){ return score > scoreLimit; }));
- };
- </script>
- <script type="text/javascript">
- function display() {
- document.write("Hello Underscore!<br>");
- document.write(getScores() + "<br>");
- document.write(getScores_() + "<br>");
- console.log("Hello Underscore!");
- console.log(getScores());
- console.log(getScores_());
- }
- </script>
- </head>
- <body>
- <div id="welcome"></div>
- <em>Underscore Demo</em>
- <p>
- <form>
- <input type="button" value="Click me!" onclick="display()" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement