getting the "this" that a function's caller was called with in JavaScript

Posted by David Morrissey on Stack Overflow See other posts from Stack Overflow or by David Morrissey
Published on 2010-05-31T03:19:12Z Indexed on 2010/05/31 3:22 UTC
Read the original article Hit count: 266

Filed under:
|
|

Is it possible to get the this that a function's caller was called with in JavaScript without passing this to the arguments in a way which supports IE as well as Firefox/Chrome et al?

For example:

var ob = {
    callme: function() {
        doSomething()
    }
}

function doSomething() {
    alert(doSomething.caller.this === ob) // how can I make this work?
}
ob.callme()

I'm starting to suspect it's not, but I thought I may as well ask as it'd make my code much shorter and easier to read.

Thanks for any information!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about this