js函数基础知识
函數(shù)是對象的一種,函數(shù)名是對象的指針
函數(shù)作為參數(shù)傳遞
var box=function(a,b) {return a(b); }function a(b){return b+10; }alert(box(a,3));?arguments.callee調(diào)用自身
function box(num){if(num<=1){return 1;}else{return num*arguments.callee(num-1);} }document.write(box(10));this表示函數(shù)所處的作用域?qū)ο?#xff0c;如果在對象里面,就表示這個對象
全局下,this表示window
var box={name:"田偉",func:function(){return this.name;} }document.write(box.func());//田偉函數(shù)的原型對象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));?
轉(zhuǎn)載于:https://www.cnblogs.com/yestian/p/6500943.html
總結(jié)
- 上一篇: 网页设计制作必须知道的10个秘诀
- 下一篇: Javascript 变量、函数的声明