Skip to content

Instantly share code, notes, and snippets.

@DavisDevelopment
Last active August 29, 2015 14:15
Show Gist options
  • Save DavisDevelopment/32dc5d7e87d28faeacd4 to your computer and use it in GitHub Desktop.
Save DavisDevelopment/32dc5d7e87d28faeacd4 to your computer and use it in GitHub Desktop.
JavaScript Tips
###
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 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?
@anthonybrown
Copy link

wouldn't it just be http://www.google.com?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment