摘要: 1. arguments为什么不是数组?如何证明?arguments 是没有数组的slice等方法的,所以不是Array类型的。验证:function testargs(){ var arr=[1,2,3]; console.log(typeof arguments.slice); console.log(typeof arr.slice);}testargs();输出:undefinedfunction当然,还可以通过其他方式来证明,比如说看constructor等等。2. 如何转为数组?使用Array的slice方法,如下:function arg2arr(){ v... 阅读全文
posted @ 2013-04-24 21:58 令狐葱★ 阅读(8272) 评论(2) 推荐(1) 编辑
摘要: // 最基础的forEach function forEach(array, action) { for (var i = 0; i < array.length; i++) { action(array[i]); } } // 测试forEach forEach(["Pear", "Apple"], function(name) { console.log(name); }); // ------------------------------------------------ //... 阅读全文
posted @ 2013-04-24 21:29 令狐葱★ 阅读(594) 评论(0) 推荐(0) 编辑
摘要: $.fn.isOnScreen = function(){ var win = $(window); var viewport = { top : win.scrollTop(), left : win.scrollLeft() }; viewport.right = viewport.left + win.width(); viewport.bottom = viewport.top + win.height(); var bounds = this.offset(); bounds.righ... 阅读全文
posted @ 2013-04-24 10:10 令狐葱★ 阅读(2358) 评论(0) 推荐(0) 编辑