如何精通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 ...
随机推荐
- git clone问题
中秋节回来上班 竟然忘记带电脑了  ̄□ ̄||还好同事有备用电脑,这要是回去拿估计上午都不用干什么了,用同事电脑当然需要安装环境,下面说一下git上遇到的问题吧 (1)首先我尝试用https方式克隆代码 ...
- 【Codeforces 492D】Vanya and Computer Game
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 第一个人攻击一次需要1/x秒 第二个人攻击一次需要1/y秒 这两个数字显然都是小数. 我们可以二分最后用了多少时间来攻击. 显然这个是有单调性 ...
- 【最大流】Escape
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/F [题意] 给定n个人和m个星球,每个人可以匹配某些星球,每个星球有一定的容量限 ...
- bzoj3295 [Cqoi2011]动态逆序对 cdq+树状数组
[bzoj3295][Cqoi2011]动态逆序对 2014年6月17日4,7954 Description 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数. ...
- ArrayAdapter的使用
package com.pingyijinren.test; import android.content.Context; import android.view.LayoutInflater; i ...
- Query on a string
You have two strings SS and TT in all capitals. Now an efficient program is required to maintain a o ...
- 易碎的鸟蛋 概率DP
1007: 易碎的鸟蛋 时间限制: 1 Sec 内存限制: 128 MB提交: 396 解决: 80[提交][状态][讨论版] 题目描述 你们知道吗?西电的跳楼塔上面有一个鸟巢.某SXBK的教授对 ...
- maven提示“编码 GBK 的不可映射字符”问题的解决
pom.xml中加上如下代码 <properties> <!-- spring版本号 --> <spring.version>4.2.3.RELEASE</s ...
- Socket编程中,阻塞与非阻塞的区别
阻塞:一般的I/O操作可以在新建的流中运用.在服务器回应前它等待客户端发送一个空白的行.当会话结束时,服务器关闭流和客户端socket.如果在队列中没有请示将会出现什么情况呢?那个方法将会等待一个的到 ...
- 教程 | 使用Sqoop从MySQL导入数据到Hive和HBase
基础环境 sqoop:sqoop-1.4.5+cdh5.3.6+78, hive:hive-0.13.1+cdh5.3.6+397, hbase:hbase-0.98.6+cdh5.3.6+115 S ...