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: