---
title: "js的constructor callee caller"
author: "hcmfys"
date: "2009-11-06T17:35:00Z"
tags: ["JavaScript", "prototype"]
slug: "js-constructor-callee-caller"
draft: false
lastmod: "2009-11-06T17:35:00Z"
id: 588776
url: "https://hcmfys.iteye.com/blog/588776"
---

&lt;script type="text/javascript"&gt;  
var name ="window method";  
function parentClass() {  
    this.name = "parentClass method";  
    this.method = function() {  
        alert(this.name);  
    }  
}  
function subClass() {  
    //var method = this.method;  
    //this.name ="test";  
    this.method = function() {  
        //method.call(this);//如果不用这一步而用下面的就会调用的是window.name;  
        //method();  
        alert("subClass method");  
    }  
}  
subClass.prototype = new parentClass();  
//subClass.prototype.constructor = subClass;

var o = new subClass();  
//alert(o.constructor);  
o.method();  
function ssonClass(){  
    o.constructor.call(this);  
};  
var h = new ssonClass();  
h.method();  
function CallLevel(){  
   if (CallLevel.caller == null){  
        return("CallLevel was called from the top level.");  
   }  
   else{  
        return("CallLevel was called by another function.");  
   }  
};  
alert(CallLevel());  
function test(){  
    alert(CallLevel());  
}  
test();  
function factorial(n){  
  if (n &lt;= 0){  
    return 1;  
  }  
  else{  
    return n * arguments.callee(n - 1);//callee是对函数自身的引用  
  }  
}  
alert(factorial(3));  
&lt;/script&gt;