Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q536 How does a function know which object called it?

irt.org | Knowledge Base | JavaScript | Misc | Q536 [ previous next ]

Q536 How does a function know which object called it?

A function can find out which function called it using the caller property:

<script language="JavaScript"><!--
function x() {
    alert('function x() was invoked by function ' + x.caller);
}

function y() {
    x();
}

y();
//--></SCRIPT>

A function can be easily passed the object in question using "this":

<script language="JavaScript"><!--
function test(what) {
    alert(what.href);
}
//--></script>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.