如何精通javascript
http://stackoverflow.com/questions/2628672/what-should-every-javascript-programmer-know
Not jQuery. Not YUI. Not (etc. etc.)
Frameworks may be useful, but they are often hiding the sometimes-ugly details of how JavaScript and the DOM actually work from you. If your aim is to be able to say “I know JavaScript”, then investing a lot of time in a framework is opposed to that.
Here are some JavaScript language features that you should know to grok what it's doing and not get caught out, but which aren't immediately obvious to many people:
That
object.propandobject['prop']are the same thing (so can you please stop usingeval, thanks); that object properties are always strings (even for arrays); whatfor...inis for (and what it isn't).Property-sniffing; what
undefinedis (and why it smells); why the seemingly-little-knowninoperator is beneficial and different fromtypeof/undefinedchecks;hasOwnProperty; the purpose ofdelete.That the
Numberdatatype is really a float; the language-independent difficulties of using floats; avoiding theparseIntoctal trap.Nested function scoping; the necessity of using
varin the scope you want to avoid accidental globals; how scopes can be used for closures; the closure loop problem.How global variables and
windowproperties collide; how global variables and document elements shouldn't collide but do in IE; the necessity of usingvarin global scope too to avoid this.How the
functionstatement acts to ‘hoist’ a definition before code preceding it; the difference between function statements and function expressions; why named function expressions should not be used.How constructor functions, the
prototypeproperty and thenewoperator really work; methods of exploiting this to create the normal class/subclass/instance system you actually wanted; when you might want to use closure-based objects instead of prototyping. (Most JS tutorial material is absolutely terrible on this; it took me years to get it straight in my head.)How
thisis determined at call-time, not bound; how consequently method-passing doesn't work like you expect from other languages; how closures orFunction#bindmay be used to get around that.Other ECMAScript Fifth Edition features like
indexOf,forEachand the functional-programming methods onArray; how to fix up older browsers to ensure you can use them; using them with inline anonymous function expressions to get compact, readable code.The flow of control between the browser and user code; synchronous and asynchronous execution; events that fire inside the flow of control (eg. focus) vs. events and timeouts that occur when control returns; how calling a supposedly-synchronous builtin like
alertcan end up causing potentially-disastrous re-entrancy.How cross-window scripting affects
instanceof; how cross-window scripting affects the control flow across different documents; howpostMessagewill hopefully fix this.See this answer regarding the last two items.
Most of all, you should be viewing JavaScript critically, acknowledging that it is for historical reasons an imperfect language (even more than most languages), and avoiding its worst troublespots. Crockford's work on this front is definitely worth reading (although I don't 100% agree with him on which the “Good Parts” are).
如何精通javascript的更多相关文章
- <精通JavaScript>---阅读笔记01
下面是阅读精通JavaScript书做的相关笔记. JS中的函数重载 函数重载必须依赖两件事情:判断传入参数数量的能力和判断传入参数类型的能力,在js中每个函数都带有一个仅在这个函数范围内作用的变量, ...
- 精通 JavaScript中的正则表达式
精通 JS正则表达式 (精通?标题党 ) 正则表达式可以: •测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式或一个信用卡号码模式.这称为数据有效性验证 ...
- 精通javascript笔记(智能社)——简易tab选项卡及应用面向对象方法实现
javascript代码(常规方式/面向过程): <script type="text/javascript"> window.onload=function(){ v ...
- 精通javascript笔记(智能社)——数字时钟
JS代码: <script type="text/javascript"> window.onload=function(){ //小于10的数字补零及数字转字符 ...
- 精通JavaScript攻击框架:AttackAPI
多年来客户端安全一直未引起人们的足够重视,但是如今情况发生了急剧转变,客户端安全已经成为信息安全领域的焦点之一.Web恶意软件.AJAX蠕虫.浏览历史暴破.登录检测.傀儡控制技术网络端口扫描以及浏览器 ...
- 精通javascript(看书笔记)
变量的类型检查 //检测类型 var str = "Hello World"; if (typeof str=="string") {//使用typeof来判断 ...
- 精通JavaScript的this关键字
小提示 阅读本文,您需要了解JS的基本常识.您将花费40分钟完成本文的阅读. JS中的this关键字让很多新老JS开发人员都感到困惑.这篇文章将对this关键字进行完整地阐述.读完本文以后,您的困惑将 ...
- 《精通javascript》几个简单的函数
转载http://www.cnblogs.com/jikey/archive/2011/07/25/2116696.html /** * 隐藏元素 * @param {String} elem */f ...
- 精彩 JavaScript 代码片段
1. 根据给定的条件在原有的数组上,得到所需要的新数组. ——<JavaScript 王者归来> var a = [-1,-1,1,2,-2,-2,-3,-3,3,-3]; functio ...
随机推荐
- Python中的列表(4)
1.遍历列表 如果想打印列表中的所有元素,则必须遍历列表. 可以使用for ... in ... 语句来遍历列表中的元素.遍历的意思 words = ['a','b','c','d'] for wor ...
- UVa 10129 单词 (欧拉通路)
题意: 输入n(n≤100000)个单词,是否可以把所有这些单词排成一个序列,使得每个单词的第一个字母和上一个单词的最后一个字母相同(例如acm.malform.mouse).每个单词最 多包含100 ...
- C#上位机开发(一)—— 了解上位机
在单片机项目开发中,上位机也是一个很重要的部分,主要用于数据显示(波形.温度等).用户控制(LED,继电器等),下位机(单片机)与 上位机之间要进行数据通信的两种方式都是基于串口的: USB转串口 — ...
- java发送短信验证码的功能实现
总结一下发送短信验证码的功能实现 (题外话:LZ是在腾讯云买的第三方(山东鼎信)短信服务平台的接口,1块钱20次的套餐来练手,哈哈,给他们打个广告,有需要的可以去购买哈,下面是购买链接短信服务平台购买 ...
- set/multiset用法详解
集合 使用set或multiset之前,必须加入头文件<set> Set.multiset都是集合类,差别在与set中不允许有重复元素,multiset中允许有重复元素. sets和mul ...
- * SPOJ PGCD Primes in GCD Table (需要自己推线性筛函数,好题)
题目大意: 给定n,m,求有多少组(a,b) 0<a<=n , 0<b<=m , 使得gcd(a,b)= p , p是一个素数 这里本来利用枚举一个个素数,然后利用莫比乌斯反演 ...
- 接龙游戏(codevs 1051)
1051 接龙游戏 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 给出了N个单词,已经按长度排好了序 ...
- 洛谷——P1458 顺序的分数 Ordered Fractions
P1458 顺序的分数 Ordered Fractions 题目描述 输入一个自然数N,对于一个最简分数a/b(分子和分母互质的分数),满足1<=b<=N,0<=a/b<=1, ...
- MongoDB小结25 - 复合唯一索引
只要满足索引的其中之一不同即可 db.blog.ensureIndex({"username":1,"blogname":1}) 作者和作品名其中之一不同即可创 ...
- linux服务器上的mysql允许远程连接
首先进入mysql: 输入GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 这里是 ...