Skip to content

Instantly share code, notes, and snippets.

@optimistanoop
Created January 13, 2017 18:33
Show Gist options
  • Save optimistanoop/9bd3cc59459fb9b80a18653ae19c4a39 to your computer and use it in GitHub Desktop.
Save optimistanoop/9bd3cc59459fb9b80a18653ae19c4a39 to your computer and use it in GitHub Desktop.
this in Js
// This is like a parameter to a function and it depends on the value binded to it.
// Binding of value to 'this' is comptely taken care by language.
// The calling object of the function is binded to "this".
var obj = {
method: function (){
console.log(this);
},
param:'value'
};
obj.method();
// here the method logs obj .
//hence calling object of the function reffered to this inside function.
// so, key here for 'this' is '.' , to the left of which obj is binded to "this" in case of calling the method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment