如何精通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.prop
andobject['prop']
are the same thing (so can you please stop usingeval
, thanks); that object properties are always strings (even for arrays); whatfor
...in
is for (and what it isn't).Property-sniffing; what
undefined
is (and why it smells); why the seemingly-little-knownin
operator is beneficial and different fromtypeof
/undefined
checks;hasOwnProperty
; the purpose ofdelete
.That the
Number
datatype is really a float; the language-independent difficulties of using floats; avoiding theparseInt
octal trap.Nested function scoping; the necessity of using
var
in the scope you want to avoid accidental globals; how scopes can be used for closures; the closure loop problem.How global variables and
window
properties collide; how global variables and document elements shouldn't collide but do in IE; the necessity of usingvar
in global scope too to avoid this.How the
function
statement 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
prototype
property and thenew
operator 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
this
is determined at call-time, not bound; how consequently method-passing doesn't work like you expect from other languages; how closures orFunction#bind
may be used to get around that.Other ECMAScript Fifth Edition features like
indexOf
,forEach
and 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
alert
can end up causing potentially-disastrous re-entrancy.How cross-window scripting affects
instanceof
; how cross-window scripting affects the control flow across different documents; howpostMessage
will 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 ...
随机推荐
- set/multiset用法详解
集合 使用set或multiset之前,必须加入头文件<set> Set.multiset都是集合类,差别在与set中不允许有重复元素,multiset中允许有重复元素. sets和mul ...
- WebLoad 脚本的用法
WebLoad 对于模拟一个HTTP 请求,一般都是 由以下三部分组成,并把这三部分包在一个Transaction里(从BeginTransation 到 EndTransaction 为止): ...
- [luoguP1056] 排座椅(sort + 模拟)
传送门 nc题,一直sort就过了 代码 #include <cstdio> #include <iostream> #include <algorithm> #d ...
- Codeforces913E. Logical Expression
现有串x=11110000,y=11001100,z=10101010,通过这三个串只用与或非三种操作到达给定的串,优先级非>或>与,可以加括号,问表达式最短的里面字典序最小的是谁,有&l ...
- Redis事务【十二】
一.概述: 和众多其它数据库一样,Redis作为NoSQL数据库也同样提供了事务机制.在Redis中,MULTI/EXEC/DISCARD/WATCH这四个命令是我们实现事务的基石.相信对有关系型数据 ...
- Charm Bracelet-POJ3624(01背包)
http://poj.org/problem?id=3624 Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- 【python】一些好的学习网址
http://www.cnblogs.com/BeginMan/p/3179302.html http://www.cnblogs.com/huxi/category/251137.html http ...
- Django学习系列之Form表单结合ajax
Forms结合ajax Forms的验证流程: 定义用户输入规则的类,字段的值必须等于html中name属性的值(pwd= forms.CharField(required=True)=<i ...
- Office 如何打印彩色照片能取得较好的效果
1 如下图所示,随便打开一个照片,点击打印,纸张大小,质量,纸张类型如下所示. 2 这样打印的设置还是不够的,因为"高级光面纸"或者类似的纸张类型,会把色彩浓度调大,相对于普通 ...
- ubuntu11.04 编译ffmpeg2.7 并生成 ffplay进行流媒体測试
源代码安装方式: 1. 先下载ffmpeg 安装包 到官网上 http://ffmpeg.org/download.html#releases 下载.选择Download gzip tarball. ...