عند تحميل النافذة ، استخدم typeof لتحديد ما إذا كانت الوظيفة موجودة في السياق
<script type = "text/javaScript"> window.onload = function () {try {if (test && typeof (test) == "function") {test () ؛ }} catch (e) {Alert ("الطريقة غير موجودة") ؛ }} test test () {Alert ("i ar the test () method") ؛ } </script>