Skip to content

Instantly share code, notes, and snippets.

@alexdelany
Forked from nedcampion/gist:4625073
Created January 24, 2013 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdelany/4625169 to your computer and use it in GitHub Desktop.
Save alexdelany/4625169 to your computer and use it in GitHub Desktop.
request = function(url, func ){
setTimeout(function(){
console.log("REQUEST", url, func);
func();
}, 1);
}
function Source(url){
this.url = url;
this.morelinks = ['NO CHANGE'];
var self = this;
this.calculate = function(url){
console.log("Calculating: " + self.url);
console.log('1: ' + self.morelinks)
var parse = function(err,resp,body){
console.log('3: ' + self.morelinks)
self.morelinks.push("ADDED ONE");
}
request(self.url, parse);
console.log('4: ' + myResults.morelinks)
}
}
myResults = new Source('http://www.reddit.com/r/videos');
myResults.calculate();
@alexdelany
Copy link
Author

Ned: as a rule, everytime you enter a new function this refers to the function you are in.

Ned: so you loose the definitions on this you defined

Ned: but if you keep a reference to the object you care about you can just refer to that variable

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