js函数

js函数:
定义方法:
静态方法:
function 函数名(虚参数){

        }
    动态匿名方法:
        var 函数名=new function([虚参数],"函数体“)
    直接量方法:
        var 函数名=new function(虚参数){
        }
调用方法:
    直接调用:函数名;
    在链接中调用:<a href="javascript:函数名()">test</a>
    在事件中调用:onclick="函数名()"
    递归调用:定义:在函数体内部调用函数自身;
                function p(i){return i<2?1:i+p(i-1);}
方法:
    function add(a,b)  
    {  
      alert(a+b);  
    }  
    function sub(a,b)  
    {  
      alert(a-b);  
    }  
    add.call(sub,3,1);//==add(3,1);

    function Animal(){  
      this.name = "Animal"; 
      this.showName = function(){   
        alert(this.name);   
      } 
    }   
    function Cat(){ 
      this.name = "Cat";    
    }   
    var animal = new Animal();  
    var cat = new Cat();    
    animal.showName.call(cat,",");   //cat
    //animal.showName.apply(cat,[]); 

    单一继承:
    function Animal(){
        this.name="fanzaijun";
        this.shwoName=function(
            return this.name;
        )
    }
    function Cat(name){
        Animal.call(this,name);
    }
    var cat=new Cat('FAFD');
    cat.showName();
    myfunc.call(func,"var"," fun");// "func" "var fun" ,var,fun是给myfunc的实参。
    myfunc.apply(func,["var"," fun"]);// "func" "var fun" var,fun是给myfunc的实参。
    apply:参数是字符串
    call:参数是数组形式的字符串。
    toString:
arguments对象:
    在javascript中,不需要明确指出参数名,就能访问它们:
    function hi(){
        if(arguments[0]=='andy'){
            return;
        }
        alert(arguments[0]);
    }
    arguments.length获取函数实参的函数。
    arguments.callee返回当前正在指向的函数。
    arguments.caller返回当前正在执行的函数名。
函数参数:

指正标识:
    this:
    callee:引用当前正在执行的函数。
    prototype:
    contructor:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值