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 and object['prop'] are the same thing (so can you please stop using eval, thanks); that object properties are always strings (even for arrays); what for...in is for (and what it isn't).

  • Property-sniffing; what undefined is (and why it smells); why the seemingly-little-known in operator is beneficial and different from typeof/undefined checks; hasOwnProperty; the purpose of delete.

  • That the Number datatype is really a float; the language-independent difficulties of using floats; avoiding the parseInt 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 using var 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 the new 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 or Function#bind may be used to get around that.

  • Other ECMAScript Fifth Edition features like indexOf, forEach and the functional-programming methods on Array; 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; how postMessage 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的更多相关文章

  1. <精通JavaScript>---阅读笔记01

    下面是阅读精通JavaScript书做的相关笔记. JS中的函数重载 函数重载必须依赖两件事情:判断传入参数数量的能力和判断传入参数类型的能力,在js中每个函数都带有一个仅在这个函数范围内作用的变量, ...

  2. 精通 JavaScript中的正则表达式

    精通 JS正则表达式 (精通?标题党 ) 正则表达式可以: •测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式或一个信用卡号码模式.这称为数据有效性验证  ...

  3. 精通javascript笔记(智能社)——简易tab选项卡及应用面向对象方法实现

    javascript代码(常规方式/面向过程): <script type="text/javascript"> window.onload=function(){ v ...

  4. 精通javascript笔记(智能社)——数字时钟

    JS代码: <script type="text/javascript">    window.onload=function(){ //小于10的数字补零及数字转字符 ...

  5. 精通JavaScript攻击框架:AttackAPI

    多年来客户端安全一直未引起人们的足够重视,但是如今情况发生了急剧转变,客户端安全已经成为信息安全领域的焦点之一.Web恶意软件.AJAX蠕虫.浏览历史暴破.登录检测.傀儡控制技术网络端口扫描以及浏览器 ...

  6. 精通javascript(看书笔记)

    变量的类型检查 //检测类型 var str = "Hello World"; if (typeof str=="string") {//使用typeof来判断 ...

  7. 精通JavaScript的this关键字

    小提示 阅读本文,您需要了解JS的基本常识.您将花费40分钟完成本文的阅读. JS中的this关键字让很多新老JS开发人员都感到困惑.这篇文章将对this关键字进行完整地阐述.读完本文以后,您的困惑将 ...

  8. 《精通javascript》几个简单的函数

    转载http://www.cnblogs.com/jikey/archive/2011/07/25/2116696.html /** * 隐藏元素 * @param {String} elem */f ...

  9. 精彩 JavaScript 代码片段

    1. 根据给定的条件在原有的数组上,得到所需要的新数组. ——<JavaScript 王者归来> var a = [-1,-1,1,2,-2,-2,-3,-3,3,-3]; functio ...

随机推荐

  1. 51NOD 2368 珂朵莉的旅行

    >>这是原题传送门<< 答案参考来自 http://www.cnblogs.com/sugewud/p/9822933.html 思路:思维题OR规律题?个人没写出来,脑子里只 ...

  2. allegro中出光绘文件遇到问题的解决办法

    一:设置好光绘文件参数后,选择check dabase before artwork后,点击生成光绘时出现错误告警信息:    database has errors:artwork generati ...

  3. 【分治】输出前k大的数

    描述 给定一个数组,统计前k大的数并且把这k个数从大到小输出. 输入第一行包含一个整数n,表示数组的大小.n < 100000.第二行包含n个整数,表示数组的元素,整数之间以一个空格分开.每个整 ...

  4. Discuz 论坛修改admin账户密码

    打开Navicat for MySQL 找到数据表 pre_ucenter_members 把密码修改为123456789 password:047099adb883dc19616dae0ef2adc ...

  5. Windows学习总结(11)——Windows批处理命令编写代码及小程序简介

    批处理(Batch)也称为批处理脚本.顾名思义,就是对某对象进行批量的处理.DOS批处理是基于DOS命令,用来自动地批量地执行DOS命令以实现特定操作的脚本.批处理是一种简化的脚本语言,它应用于DOS ...

  6. [luoguP1439] 排列LCS问题(DP + 树状数组)

    传送门 无重复元素的LCS问题 n2 做法不说了. nlogn 做法 —— 因为LCS问题求的是公共子序列,顺序不影响答案,影响答案的只是两个串的元素是否相同,所以可以交换元素位置. 首先简化一下问题 ...

  7. CSS font-family 属性

    CSS font-family 属性 实例 为段落设置字体: p { font-family:"Times New Roman",Georgia,Serif; } 亲自试一试 浏览 ...

  8. JVM(三):深入分析Java字节码-上

    JVM(三):深入分析Java字节码-上 字节码文章分为上下两篇,上篇也就是本文主要讲述class文件存在的意义,以及其带来的益处.并分析其内在构成之一 ---字节码,而下篇则从指令集方面着手,讲解指 ...

  9. 05-js德玛==和===判断

    <html> <head> <title>js的特殊关系运算符</title> <meta charset="UTF-8"/& ...

  10. NOIP 2010 机器翻译

    P1540 机器翻译 题目背景 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 题目描述 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于 ...