Last active
October 21, 2015 14:22
-
-
Save bydga/5eaa4c99399cf1ad4bfe to your computer and use it in GitHub Desktop.
Node workshop examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //načtení externího modulu, který parsuje/sestavuje url (nodejs) | |
| var url = require("url") | |
| doHttpRequest = function() { | |
| //do nothing | |
| return | |
| } | |
| var work = function(){ | |
| url = "http://api.zcu.cz" | |
| doHttpRequest(url) | |
| } | |
| //něco si naparsujeme | |
| var parsed = url.parse("http://kiv.zcu.cz:8080/articles?page=1") | |
| console.log(parsed) | |
| //trochu práce | |
| work() | |
| //něco si… TypeError: Object http://api.zcu.cz has no method 'parse' | |
| parsed = url.parse("http://kiv.zcu.cz:8080/articles/list?page=1") | |
| console.log(parsed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fruits = ["apple", "pear", "banana", "mango"] | |
| var functions = [] | |
| //EDIT THIS: | |
| for (var i=0; i<fruits.length; i++) { | |
| var fruit = fruits[i] | |
| functions.push( | |
| function() { | |
| console.log(fruit) | |
| } | |
| ) | |
| } | |
| //DO NOT EDIT BEYOND THIS LINE | |
| for (var j=0; j<functions.length; j++) { | |
| functions[j]() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment