-
-
Save jaseemabid/1165210 to your computer and use it in GitHub Desktop.
basic example of this object
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
var a, b, c, d, e; | |
a = function(obj) { | |
return this; | |
} | |
// when you call the function in 'function form' 'this' is window object | |
a(); // window | |
// Always! Even if you define and call it inside another function | |
(function() { | |
var aa = a; | |
var bb = aa(); | |
return bb; // window | |
})(); | |
// when you call it as a method of some object 'this' will be that object | |
b = { a : a }; | |
b.a(); // b object | |
// when you use the function as a constructor with 'new' operator new | |
// object will be created inside, assigned to 'this' and then returned | |
c = new a(); // object a - instance of the a constructor function | |
// when you use the function as a callback for some events on DOM element | |
// it will be the context of the function | |
d = document.getElementById('myDiv'); | |
d.addEventListener('click', a, false); // HTMLDivElement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment