Skip to content

Instantly share code, notes, and snippets.

@cld-santos
Last active August 29, 2015 14:00
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 cld-santos/11006572 to your computer and use it in GitHub Desktop.
Save cld-santos/11006572 to your computer and use it in GitHub Desktop.
This sample show how the 'this' keyword refer to a different objects, and thoose scopes are both, global or object related depends on where are you in the current moment.
console.clear();
function Blog(){
//bad pratice avoid this
//if (!(this instanceof blog))
// return new blog();
function internal(){
console.log('internal:' + this);
}
this.external = function(){
console.log('external:' + this);
internal();
}
this.external();
}
console.log('called with global scope');
Blog();
console.log('called with Blog Object Scope');
var blogObj = new Blog();
blogObj.external();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment