オブジェクトの作成元の参照を取得します.
object.constructor
以下にconstructorプロパティを使用したサンプルコードを示します.
<html>
<head>
<title>constructorプロパティのサンプルコード</title>
</head>
<body>
<script type="text/javascript" language="javascript">
var err = new Error();
/* constructorプロパティの値を表示 */
document.write(err.constructor + "<br />");
if (err.constructor == Error) {
document.write("Errorオブジェクト");
} else {
document.write("Errorオブジェクト以外");
}
</script>
</body>
</html>
サンプルコードの実行結果は以下のようになります.
function Error() { [native code] } Errorオブジェクト
スポンサード リンク