js的constructor callee caller

<script type="text/javascript">
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 <= 0){
    return 1;
  }
  else{
    return n * arguments.callee(n - 1);//callee是对函数自身的引用
  }
}
alert(factorial(3));
</script>
posted on 2009-11-06 17:35  hcmfys_lover  阅读(271)  评论(0编辑  收藏  举报