如何精通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 ...
随机推荐
- Matlab学习笔记(五)
三.矩阵运算 (一)矩阵函数和特殊矩阵 常见的矩阵处理函数 表3-1 常见的矩阵函数 函数 说明 /或\ 矩阵除法中的左除或右除,可以用于求解线性方程组 accumarray(ind,val) ...
- 面试高峰期,如何应对面试官的jvm刁难,特写一篇jvm面经(第一部)
已经进入三月份,正所谓金三银四,正是一年最好的招聘期,想必我的公号粉丝们一定有不少想要跳槽的吧,哈哈,/**偷偷告诉你们其实小编也准备跳槽*/(我要加个注释,被老板知道可就完蛋了),说到面试,想必大家 ...
- 牛客网暑期ACM多校训练营(第二场)B discount
链接:https://www.nowcoder.com/acm/contest/140/B来源:牛客网 题目描述 White Rabbit wants to buy some drinks from ...
- 如何使用Mysql Workbench导出一整个sql文件,sql包?
1. 点击Management ; 2. 点击Data Export 3. 点击需要备份的数据名字并打钩 1是点击查看2是选择 4. 在右下方选择要要备份的类型(框架,数据,框架+数据) 5. 选择你 ...
- 2018/2/27 Activiti教程之创建流程篇(与Springboot整合版)一
因为电脑还在托运中,现在手上这台垃圾电脑实在是没法玩微服务,所以趁着这两天玩玩Activiti吧. 说实话,在学习Activiti中走了N多弯路,最大的原因就是网上没有一个完整(好)的教程,甚至连官方 ...
- msp430入门编程11
msp430中C语言的模块化头文件及实现11 msp430中C语言的模块化头文件及库文件12 msp430入门学习 msp430入门编程
- Linux下汇编语言学习笔记7 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- MySQL主主复制搭建教程收集(待实践)
先收集,后续再实践. http://www.cnblogs.com/ahaii/p/6307648.html http://blog.csdn.net/jenminzhang/article/deta ...
- omnidazzle是mac的画笔工具
先使用命令 brew cask install omnidazzle 试试,不行参考下面: http://macappstore.org/omnidazzle/
- 从头认识Spring-2.3 注解装配-@autowired(4)-required(2)
这一章节我们来继续具体讨论一下@autowired里面的參数required.在多构造器注入的情况. 1.domain(重点) 蛋糕类: package com.raylee.my_new_sprin ...