標籤:對象冒充 藍色 box 表示 type 函數名 var 紅色 參數
函數是對象的一種,函數名是對象的指標
函數作為參數傳遞
var box=function(a,b) { return a(b);}function a(b){ return b+10;}alert(box(a,3));
arguments.callee調用自身
function box(num){ if(num<=1){ return 1; }else{ return num*arguments.callee(num-1); }}document.write(box(10));
this表示函數所處的範圍對象,如果在對象裡面,就表示這個對象
全域下,this表示window
var box={ name:"田偉", func:function(){ return this.name; }}document.write(box.func());//田偉
函數的原型對象prototype 有2個方法call(),replay();
function box(a,b){ return a+b;}function sum(c,d){ return box.apply(this,[c,d]);
//return box.apply(this,arguments);}document.write(sum(3,4));
//冒充box,this表示box在window下面
function box(a,b){ return a+b;}function sum(c,d){ return box.call(this,c,d);}document.write(sum(3,555));
call 對象冒充
var color="藍色";var box={ color:"紅色"}function showcolor() { return this.color;}document.write(showcolor.call(box));
js函數基礎知識