構文
 
  関数オブジェクト名.constructor
総合 インデックス
プロパティ
FirefoxIE

説明

  • オブジェクトの作成元である関数名の値を取得する。

用例

ボタンフォームをクリックしたとき,「MyFunction」関数の処理が発生するようにしている。「MyFunction」の処理では,「constructor」を使ってこの関数の作成元を取得し,アラート・ダイアログボックスに表示する。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>constructor</title>
<script type="text/javascript">
<!--
function MyFunction() {
    if (MyFunction.constructor == null) {
        alert("このファンクションはフォームのTopから呼ばれました");
    }
   else { alert("このファンクションは" + MyFunction.constructor
+ "から呼ばれました"); } } //--> </script> <style type="text/css"> <!-- body { background-color: #ffffff; } --> </style> </head> <body> *オブジェクトの作成元を参照する <p> <form> <input type="button" value=" クリックしてください "
onclick="MyFunction()"> </form> </p> </body></html>

この用例を実行する