一、callee属性 和 caller属性。数组
区别:二者的调用对象不一样app
arguments.callee:指向拥有这个arguments对象的函数,在递归运算中常常用到。函数
functionName.caller:在函数中经过函数名来调用,这个属性中保存着调用当前函数的函数引用。functionName也可使用arguments.callee来代替 。 学习
function out(){ console.log(arguments.callee); } out(); // ƒ out(){console.log(arguments.callee);}
function out(){ inner(); } function inner(){ console.log(arguments.callee.caller) } out(); // ƒ out(){inner();}
二、arguments.length 和 function.lengththis
区别:很明显,调用这个属性的对象不一样。arguments.length表示调用函数时实际传递的参数个数,有可能与函数定义时设置的参数个数不一样。function.length表示函数但愿接收的参数个数即定义函数时声明的形参的个数。spa
function test(a,b){ console.log('arguments.length = '+arguments.length); console.log('函数test.length = '+test.length); } test(1,2,3,4); // arguments.length = 4, 函数test.length = 2
三、在ECMAscript5中,prototype属性时不可枚举的,所以使用for-in没法获取该属性的值。prototype
四、apply方法和call方法code
这两个方法的用途都是在特定的做用域中调用函数,实际上等于设置函数体this对象的值。对象
区别:主要是除了第一个参数以外的其余参数类型不一样。apply接收arguments对象和数组,call只能逐个传入参数。blog
function sum(num1,num2){ return num1 + num2; } function callSum1(num1,num2){ return sum.apply(this,arguments); // 传入arguments对象 } function callSum2(num1,num2){ return sum.apply(this,[num1,num2]); // 传入数组 } function callSum3(num1,num2){ return sum.call(this,num1,num2); //逐个列举参数 } console.log(callSum1(10,10)); //20 console.log(callSum2(10,10)); //20 console.log(callSum3(10,10)); //20
五、typeof 和 instanceof
这两个操做符均可以用来检测类型,可是typeof只能检测基本数据类型,好比:字符串、数值、布尔值、undefined等,若是变量是一个对象或者null,使用typeof只会返回“object”。
使用instanceof能够知道检测的值是什么类型的对象。
var num = 1; var str = 'hello'; var b = true; var u; var n = null; var arr = [1,2,3]; console.log(typeof num); //number console.log(typeof str); // string console.log(typeof b); // boolean console.log(typeof u); // undefined console.log(typeof n); // object console.log(typeof arr); // object console.log(arr instanceof Array); // true
六、document.documentElement.scrollTop 和 document.body.scrollTop
页面具备 DTD(或者说指定了 DOCTYPE)时,使用 document.documentElement。
页面不具备 DTD(或者说没有指定了 DOCTYPE)时,使用 document.body。
为了兼容,可使用以下代码:
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
不断学习,不断完善中~~~