- 浏览: 2574247 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (1286)
- js-oop (2)
- js-window (10)
- js-event (19)
- js-string (37)
- js-array (27)
- js-page (4)
- js-dom (62)
- js-lang (8)
- js-number (7)
- js-platform (3)
- js-object (15)
- js-element (3)
- js-browser (7)
- js-url (6)
- js-date (10)
- css基础 (48)
- css优化 (15)
- html基础 (17)
- html标签 (19)
- js基础 (117)
- js-兼容性差异 (33)
- js引擎 (3)
- js性能 (14)
- json (6)
- jQuery源码浅析 (43)
- web mobile开发资料 (78)
- js跨域 (2)
- html5 (74)
- html5-canvas (7)
- css3 (53)
- 浏览器 (5)
- api设计学 (3)
- js-加载 (3)
- linux (37)
- 架构师 (1)
- php (2)
- self开发的脚本库--凤凰 (2)
- web应用名词 (6)
- javascript新特性翻译 (8)
- ajax (6)
- jQuery动画效果 (7)
- prototype的解读 (13)
- 优秀插件翻译 (1)
- css解决方案 (26)
- 数据库 (2)
- english daily (59)
- 浏览器内核探究 (1)
- jQuery插件介绍 (9)
- jquery基础篇 (26)
- chrome浏览器问题整理 (14)
- js选择器那些事 (3)
- 前端框架 (26)
- Firefox私有属性 (11)
- webkit私有属性集合 (17)
- 书籍推荐 (21)
- 数据结构 (1)
- 网站建设相关 (7)
- 好文翻译 (2)
- 个人作品 (3)
- kissy的解读 (4)
- css-layout(布局研究) (5)
- less研究 (1)
- YUI探究 (1)
- hash探究 (1)
- js动画 (7)
- 前端面试题 (37)
- css书写规范 (1)
- js模板引擎 (6)
- js模块化 (19)
- 编写高质量代码 (3)
- 性能探究--应用协议 (2)
- 前端图像处理 (19)
- Mac OS相关 (21)
- 正则表达式 (11)
- 离线应用相关 (0)
- 前端工具 (65)
- nodeJS (55)
- jquery优化篇 (2)
- 设计模式探究系列 (3)
- windows7 (2)
- IE10 (10)
- 微博开放平台探究 (2)
- 常用web服务接口 (1)
- 数据存储相关 (8)
- 零时文件 (2)
- jQuery Mobile (16)
- backbone (15)
- underscore (22)
- sass (11)
- android (3)
- phonegap (10)
- IE私有 (11)
- qwrap (8)
- git (14)
- chrome extensions (5)
- freemarker (11)
- angularJS (3)
- seo (2)
- markdown (3)
- css动画 (4)
- 安卓开发 (2)
- React (7)
- 活动页技术 (1)
- 网络安全 (3)
- grunt (7)
- Lo-Dash (3)
- 前端国际化 (4)
- 版本控制 (2)
- 盒模型 (4)
- 微信开发 (1)
- Mock数据工具 (1)
- sails (1)
- vim (1)
- js-color (1)
- iOS 基础 (43)
最新评论
-
jertom:
<div id="showInfo" ...
addEventListener等事件监听的参数细谈 -
乌托邦国王:
引用[u][/u]
css3动画属性系列之transform细讲移动translate -
hvang1988:
能提供附件下载吗,找不到js库,google封了访问不了
Syntaxhighlighter---代码高亮插件介绍 -
sscsacdsadcsd:
我的天 那到底是为什么function是object我看und ...
typeof func ==='function'的疑惑 -
wkjiangwk:
试了,没用,你们从不去测试。
介绍一下x-webkit-speech -------实现语音输入
书写高质量JavaScript代码的要点(The Essentials of Writing High Quality JavaScript)翻译
前言:
1、文章尾部带有原文的链接和来自zhangxinxu的翻译文章。
2、本文只是节选了部分更直接性的言论,去除了一些“无关的”言论。
3、只是个人学习+练习英语的topic
4、为了方便大家学习,加上了尾部部分单词的意思
正文:
- 书写可维护的代码 (Writing Maintainable Code)
可维护的代码意味着如下:
1、可读的
2、一致的
3、可预见的
4、看起来出自同一个之手写的
5、有记录的
- 最小化全局变量(Minimizing Globals)
myglobal = "hello"; //不推荐的方式 console.log(myglobal ); //"hello" console.log(window.myglobal ); //"hello" console.log(window["myglobal"] ); //"hello" console.log(this.myglobal); //"hello"
- 全局变量的问题(The Problem with Globals)
function sum(x,y){ //不推荐的写法:隐式的全局变量 result = x +y; return result; }
这段代码中,result在使用的过程中没有被声明,代码正常工作,但是在函数调用之后在全局空间就多了一个变量result,这恰恰是问题的根源。
经验往往告诉我们始终使用var来声明变量,正如改进版的sum()函数展示的:
function sum(x,y){ var result = x+y; return result; }
- 构造函数首字母大写(Capitalizing Constructors)
var adam = new Person();
因为构造函数还也只是函数,仅仅看函数名可以帮助告诉你这个是不是一个构造函数还是一个正常的函数。
以首字母大写来命名构造函数具有暗示作用。使用小写命名的函数和方法意味着不应该使用new调用。
function MyConstructor(){...}
function myFunction(){...}
- switch 形式(switch Pattern)
你可以通过类似于下面的模式的switch语句增强可读性和健壮性。
var inspect_me = 0, result = ''; switch(inspect_me ){ case 0: result ='zero'; break; case 1: result ='one'; break; default: result = 'unknow'; }
这个简单的例子遵循的风格如下:
1、每一个case与switch对齐(花括号缩进规则除外)
2、每一个case中代码缩进
3、每一个case以break结束
4、避免贯穿(当你故意忽略break)。如果你确信贯穿是最好的办法, 确信记录这些情况,因为对于你代码的一些阅读 者来说,它可能看起来是错误的。
5、以default结束switch:确保总有健全的结果,技术无情况匹配的时候。
- 避免隐式类型转换(Avoiding Implied Typecasting)
var zero = 0; if(zero === false){ //没有执行,因为zero是0不是false } if(zero == false){ //执行了 }
- parseInt()下的数值转换(Number Conversions with parseInt())
var month = "06", year = "09"; month = parseInt(month,10); //6 year = parseInt(year,10); //9
+ "08"; //8 Number("08"); //8 typeof == number
这些通常快于parseInt(),因为parseInt()方法,顾名思义,解析转换不是那么简单的。但是如果你想输入“08 hello”这样的,parseInt()将会返回一个数字,而其他返回NaN.
parseInt("08 hello"); //0 +"08 hello"; //NaN Number("08 hello"); /NaN
部分原文的单词翻译:
1、maintainable -------可维持的,主张的
2、consistent -------一致的
3、predictable ------可预见的
4、snippet -----片段
5、convenience -----方便
6、variable -----可变化的,变量
7、declare -----声明,宣布
8、invoke -----调用
9、hint -----暗示
10、indicate -----意味着
11、robustness ----健壮性
12、sane ----健全的
13、approach ----方法
14、indent ----缩进
15、robust ----健全的
16、imply ----暗指
17、conversion ----转换
扩展阅读:
1、http://net.tutsplus.com/tutorials/javascript-ajax/the-essentials-of-writing-high-quality-javascript/
2、http://www.zhangxinxu.com/wordpress/?p=1173
发表评论
-
TweenMax
2014-03-31 17:32 998TweenMax: 在线调用:http ... -
动画框架之Sprite
2014-02-18 13:44 945Sprite.js An ... -
bootstrap分拆之table
2013-07-11 14:44 0本文整理一下bootstrap中tabl ... -
自执行函数相关
2013-05-07 20:39 1365整理几种自执行函数: 在最前最后加括 ... -
jquery全屏版插件
2013-04-11 13:29 0先贴上代码: ;(function($) ... -
好东西之--获取ie版本号的一种方式
2013-05-08 10:22 1532先看一段jqm1.1.0版本的代码: ... -
backboneJS
2013-02-21 17:05 1330backbone.js 重量级js ... -
一淘首页优化总结
2013-02-01 17:10 0尽量减少DOM节点 不需要初始加载就渲染 ... -
Sizzle简介
2013-01-28 12:21 1473Sizzle 从jq的1.3开始,jq也采用S ... -
a javascript module pattern
2013-01-21 14:13 1382本文介绍一种不错的module pattern. ... -
严格模式探究
2013-01-18 17:32 1425探究一下严格模式 ... -
响应式框架Foundation简介
2013-01-15 19:34 0响应式框架:Foundation 官方地址: ... -
Turn.js简介
2013-01-14 11:18 1486本文简单介绍一下turn.js这个东东! 主 ... -
AppJS简介
2013-01-10 19:49 1995本文介绍一下AppJs. 官网:http:// ... -
移动框架Zeptp介绍
2012-12-13 13:10 1574本文简单介绍一下Zepto. 基于移 ... -
关于页面依赖文件加载失败处理的一种“独特”设计
2012-12-07 17:00 2380问题与需求: ... -
关于页面依赖文件加载失败处理的一种“独特”设计
2012-12-07 16:59 1问题与需求: 某个项目首页或者首屏在弱网络环境下,或 ... -
内容复制兼容性解决方案之ZeroClipboard
2012-12-03 13:24 2595Zero Clipboard 1、简介: J ... -
项目开发设计之设计文档编写规范
2012-11-18 14:57 3474前言: 慢慢地,很多fe也会接触到一些比较大中型的项目 ... -
初识BigPipe
2012-11-12 14:38 1530BigPipe ------ 一个重新设计的基础动态 ...
相关推荐
It focuses on the function and design of the various components necessary to process information digitally. We present computing systems as a series of layers, starting with low-level hardware and ...
The Art of Software Architecture—Design Methods and Techniques Introduction Chapter 1 - Introduction to Software Architecture Chapter 2 - The Software Product Life Cycle Chapter 3 - The ...
The Essentials of Risk Management, 2nd Edition.pdf
The Essentials Of Finance And Accounting For Nonfinancial Managers
JavaScript and JSON Essentials is a step-by-step guide that will introduce you to JSON and help you understand how the lightweight JSON data format can be used in different ways either to store data ...
worldwide, Essentials of UMTS will enable you to grasp the key concepts quickly. It assumes no previous knowledge of mobile telecommunication theory, and is structured around the operation of the ...
《计算机组成原理与系统结构》,经典教材,chm版本 难得啊
ESSENTIALS OF ROBUST CONTROL,英文好书!
提供详细而全面但易于遵循的使用JavaScript开发强大,动态网页的指南。
Essentials of Stochastic Processes课后习题答案
JS超级名著《Essentials of Javascript》目录: JavaScript 1 JavaScript syntax 18 JavaScript Style Sheets 43 JavaScript engine 44 Ajax (programming) 48 AJAX.OOP 51 ?: 52 Appcelerator Titanium 57 ...
Essentials of Rubin's Pathology, Sixth Edition, is a condensed version of the main title, Rubin's Pathology, 6e. Targeted to students in allied health fields, including dentistry, nursing, physical ...
ESSENTIALS OF BUSINESS COMMUNICATION, 9TH EDITION presents a streamlined approach to business communication that includes unparalleled resources and author support. ESSENTIALS OF BUSINESS ...
The Essentials of Risk Management _ APRM考照指定用書
Essentials of Computer Architecture, Second Edition by Douglas Comer 2017 | ISBN: 1138626597 | English | 535 pages | True PDF | 4 MB This easy to read textbook provides an introduction to computer ...
In-depth coverage of key issues, combined with a strong focus on software quality, makes Essentials of Software Engineering, Third Edition the perfect text for students entering the fast-growing and ...
Coding Theory The Essentials
Essentials of Programming in Mathematica 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除