![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
js学习
iteye_19565
这个作者很懒,什么都没留下…
展开
-
javascript悬挂
先看一段代码: var scope = "global";function f() {console.log(scope); var scope = "local"; console.log(scope); }这段代码的输出结果是:undefinedlocal js犀牛书上的解释是,与全局变量同名的局部变量在整个函数内部覆盖全局变量。简而言之,所...原创 2011-07-21 19:22:58 · 228 阅读 · 0 评论 -
for/in不适合array遍历的情形
1、for/in将遍历从原型中继承的属性。 因此遍历数组的时候有诸多不便,需要通过以下方式保证属性是属于当前数组而不是继承来的。 for( var i in a){ if (!a.hasOwnProperty(i)) continue; //循环语句 } 2、for/in遍历对象的时候顺序是不定的。 数组中可能有Number,String,O...原创 2011-07-23 13:39:31 · 505 阅读 · 0 评论 -
call和apply到底有啥用
为什么有这两个函数呢?们到底可以做什么?mozilla官方的文档让我看到了一点端倪:1、call函数可以让你从已有的对象中继承一个方法,而不必为新对象写一个新的方法With call, you can write a method once and then inherit it in another object, without having to rew...2011-07-24 20:49:26 · 239 阅读 · 0 评论 -
闭包也就这玩意
闭包也叫closure这东西听起来挺玄乎,《js犀牛书》上搞了一计数器作为例子,如下: function counter() { var n = 0; return { count: function() { return n++; }, reset: function() { n = 0; } };}var c =...原创 2011-07-25 15:34:38 · 109 阅读 · 0 评论