Last active
August 29, 2015 14:00
-
-
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.
This file contains 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
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