Last active
August 29, 2015 14:15
-
-
Save DavisDevelopment/32dc5d7e87d28faeacd4 to your computer and use it in GitHub Desktop.
JavaScript Tips
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
### | |
This file assumes the existence of some function 'request', which takes a URL as it's first argument, | |
and a callback as it's second. | |
The callback, when the Request has completed, will be invoked with the HTTP response received from the URL as it's first argument | |
### | |
#- The HTML data received from google.com | |
html_data = [null] | |
#- Make a request to google.com, and get the response | |
request 'http://www.google.com', (response) -> | |
#- Check that [response] is not 'null' | |
if response? | |
#- Sync [response] into the global scope | |
html_data[0] = response | |
#- Now, print that result to the console | |
console.log html_data[0] | |
#- What do you think was just printed? |
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
/** | |
* This file assumes the existence of some function 'request', which takes a URL as it's first argument, | |
* and a callback function as it's second. | |
* The callback, when the Request has completed, will be invoked with the HTTP response received from the URL as it's first argument | |
*/ | |
//- The HTML data received from Google.com | |
var html_data = null; | |
/** | |
* Make a request to google.com, and get the response | |
*/ | |
request('http://www.google.com', function(response) { | |
//- Check that [response] is not 'null' | |
if ((typeof response !== 'undefined') && (response !== null)) { | |
//- Sync [response] into the global scope | |
html_data = response; | |
} | |
}); | |
//- Now, print that result to the console | |
console.log( html_data ); | |
//- What do you think was just printed? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wouldn't it just be
http://www.google.com
?