JavaScript:TheDefinitive Guide
5ed,David Flanagan, O’Reilly Media Inc. 2006, China Machine Press 2007
Brendan Eich, Father of JavaScript
Douglas Crockford
ECMA, European Computer Manufacturer’s Association,http://www.ecma-international.org
ECMA-262 v3,Netscape & Mozilla Foundation JavaScript 1.5, MicrosoftJscript 5.5
1. Core JavaScript
1.1 词法结构你没有
1.1.1 Charset:Unicode
1.1.2 Case:ensitive
1.1.3 Blank:Ignore, Space, Tab, Newline
1.1.4 ;:Optional
1.1.5 Comment://, /**/
1.1.6 Literal
1.1.6.1 Integer
1.1.6.1.1 decimal
1.1.6.1.2 octal
1.1.6.1.3 hexa
1.1.6.2 float:(+|-)(igits)(.digits)(e|E(+|-)digits)
1.1.6.3 string:’’,””,\
1.1.6.4 boolean:true,false
1.1.6.5 regular expression:/exp/
1.1.6.6 null:null
1.1.6.7 undefined:undefined
1.1.6.8 object:{}
1.1.6.9 array:[]
1.1.6.10 function:function(){}
1.1.7 Identifier:alpha,_,$,num: Unicode
1.1.8 Keywords
1.1.8.1 Reserved
Break,continue,return,
switch/case/default,do/while,while,for,for/in,if/else,
Try/catch/finally,throw,
Delete,instanceof,new,this,typeof,var,with
False,true,function,null,void
1.1.8.2 Extended
Abstract,extends,implements,interface,class,
Const,final,protected,private,public,
native,static,transient,volatile,
super,synchronized,throws,
package,import,export,
Byte,Boolean,char,double,float,int,enum,long,short,
Goto,
Debugger,
1.1.8.3 ECMA v4
As,is,namespace,use
1.1.8.4 Predefined
arguments,
Infinity,NaN,undefined,
isFinite,isNaN,parseFloat,parseInt,
Array,Boolean,Function,Number,Object,String,
Date,Math,RegExp,
Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,
decodeURI,decodeURIComponent,encodeURI,
escape,eval,unescape,
1.2 Data Type
1.2.1 number
Number.MAX_VALUE,MIN_VALUE,NaN,POSITIVE_INFINITY,NEGATIVE_INFINITY
1.2.1.1 integer
1.2.1.1.1 decimal: -2^53~2^53(9百万亿),-2^31~2^31-1(2十亿)
1.2.1.1.2 octal: 0
1.2.1.1.3 hexa: 0x,0X
1.2.1.2 float:[digits][.digits][(E|e)[(+|-)]digits]
1.2.2 string:’’,””,\
1.2.2.1 转义序列
\0,
\b,\t,\n,\v,\f,\r,\’,\”,\\,\xXX,\uXXXX,\XXX
1.2.3 boolean
true,false
1.2.4 function
Function(),lambda(函数直接量)
1.2.5 object
Object(),{}
1.2.6 array
Array(),[]
1.2.7 null:null
1.2.8 undefined:undefined
1.2.9 Date: Date()
1.2.10 RegExp: RegExp(), //
1.2.11 Error: Error, EvalError,RangeError, ReferenceError,SyntaxError,TypeError, URIError
1.2.12 Wrapper: valueOf()
1.2.13 Number: Number(), parseInt(),parseFloat(),- 0,
1.2.14 Boolean: Boolean(), !!
1.2.15 String: String(), + “”,toString(),
1.3 Variable
1.3.1 type: declare,initialize
1.3.2 scope: global, local
1.3.3 no block scope, scope chain,global object & call object
1.4 expression
1.4.1 operator
1.4.1.1 number: unary,binary,ternary
1.4.1.2 type: lvalue
1.4.1.3 precedence
1.4.1.4 associativity
1.4.1.5 category
1.4.1.5.1 算术运算符: +, -, *, /, %, -(unary), +(unary), ++, --,
1.4.1.5.2 相等运算符: ==, ===, !=, !==
1.4.1.5.3 关系运算符
1.4.1.5.3.1 比较运算符: >, <, <=, >=,
1.4.1.5.3.2 in运算符
1.4.1.5.3.3 instanceof运算符
1.4.1.5.4 字符串运算符: +, >, <
1.4.1.5.5 逻辑运算符: &&, ||, !
1.4.1.5.6 位运算符:&, |, ~, ^, >>, <<, >>>]
1.4.1.5.7 赋值运算符:=, +=, -=, *=, /=, >>=, <<=, >>>=, &=, |=,^=
1.4.1.5.8 其他运算符
1.4.1.5.8.1 条件运算符: ?:
1.4.1.5.8.2 typeof运算符: number,string,boolean,object,function,undefined
1.4.1.5.8.3 对象创建运算符:new
1.4.1.5.8.4 delete运算符
1.4.1.5.8.5 void运算符
1.4.1.5.8.6 逗号运算符: ,
1.4.1.5.8.7 数组和对象存取运算符:[],.
1.4.1.5.8.8 函数调用运算符: ()
1.4.2 列表
优先级P | 结合性A | 运算符 | 运算数类型 | 所执行的操作 |
15 | L | . |
|
|
| L | [] |
|
|
| L | () |
|
|
| R | new |
|
|
14 | R | ++ |
|
|
| R | -- |
|
|
| R | - |
|
|
| R | + |
|
|
| R | ~ |
|
|
| R | ! |
|
|
| R | delete |
|
|
| R | typeof |
|
|
| R | void |
|
|
13 | L | *, /, % |
|
|
12 | L | +, - |
|
|
| L | + |
|
|
11 | L | << |
|
|
| L | >> |
|
|
| L | >>> |
|
|
10 | L | <, <= |
|
|
| L | >, >= |
|
|
| L | instanceof |
|
|
| L | in |
|
|
9 | L | == |
|
|
| L | != |
|
|
| L | === |
|
|
| L | !== |
|
|
8 | L | & |
|
|
7 | L | ^ |
|
|
6 | L | | |
|
|
5 | L | && |
|
|
4 | L | || |
|
|
3 | L | ?: |
|
|
2 | R | = |
|
|
| R | *=, /=, %=, +=, -=, <<=, >>=, >>>=, &=, ^=, |= |
|
|
1 | L | , |
|
|
1.5 statement
1.5.1 表达式语句: 赋值语句, 函数调用
1.5.2 compound statement
1.5.3 list
statement | syntax | function |
break | break; break label; |
|
case | case expression: |
|
continue | continue; continue label; |
|
default | default: |
|
do/while | do statement while (expression); |
|
空语句 | ; |
|
for | for (initialize ; test ; increment) statement |
|
for/in | for (variable in object) statement |
|
function | function funcname([arg1[…, argn]]) { statements } |
|
if/else | if (expression) statement1 [else statement2] |
|
label | identifier: statement |
|
return | return [expression]; |
|
switch | switch (expression) { statements } |
|
throw | throws expression; |
|
try | try { statements } catch (identifier) { statements } finally { statements } |
|
var | var name_1 [ = value_1] [, …, name_n [ = value_n]] |
|
while | while (expression) statement |
|
with | with (object) statement |
|
1.6 object & array
1.6.1 object
1.6.1.1 create object: {}, Date()
1.6.1.2 object property
1.6.1.2.1 property enumeration: for (varprop in obj)
1.6.1.2.2 property exists?: if ( prop inobj), if (obj.prop != undefined), if(obj.prop)
1.6.1.2.3 delete property: delete obj.prop;
1.6.1.3 Object properties & methods
1.6.1.3.1 constructor: obj.constructor =SomeObject; if((typeof o == ‘object’) && (o instanceof Date))
1.6.1.3.2 toString()
1.6.1.3.3 toLocaleString()
1.6.1.3.4 valueOf()
1.6.1.3.5 hasOwnProperty()
1.6.1.3.6 propertyIsEnumerable()
1.6.1.3.7 sPrototypeOf():Object.prototype.isPrototypeOf(o)
1.6.2 array
1.6.2.1 create array: [], Array()
1.6.2.2 add element
1.6.2.3 delete element: delete,Array.shift(), Array.pop(), Array.splice()
1.6.2.4 array length: length
1.6.2.5 enumeration: for(var I = 0; I <a.length; i++) {}
1.6.2.6 array methods
1.6.2.6.1 join():a.join()
1.6.2.6.2 reverse(): a.reverse()
1.6.2.6.3 sort(): a.sort()
1.6.2.6.4 concat()
1.6.2.6.5 slice()
1.6.2.6.6 splice()
1.6.2.6.7 push(), pop()
1.6.2.6.8 unshift(), shift()
1.6.2.6.9 toString(), toLocaleString()
1.7 function
1.7.1 function(){}, Function()
1.7.2 parameter: arguments.length,arguments.callee,argument[]
1.7.3 function properties & methods
1.7.3.1 length:arguments.length,args.callee.length
1.7.3.2 prototype
1.7.3.3 apply(obj, [paras])
1.7.3.4 call(obj, para1,…, paran)
1.8 class
1.8.1 constructor
1.8.2 module
1.8.3 namespace
1.9 regexp
1.9.1 definition: RegExp, //
1.9.2 literal:alpha, num, escape(\0,\t,\n,\v,\f,\r,\xnn,\uxxxx,\cX),(^ $ . * + ? = ! : | \ / () [] {})
1.9.3 character class: […],[^…], .\w[a-zA-Z0-9_] \W \s \S \d \D [\b]退格
1.9.4 重复: {n, m}, {n, },{n} ? + *, 非贪婪的重复{n,m}?,??,+?,*?
1.9.5 选择,分组,引用: |, (…), (?:…)只组合不记忆, \n
1.9.6 边界: ^ $ \b \B (?=p) (?!p)
1.9.7 标志: i g m
1.9.8 RegExp: exec(text)返回匹配数组,test(text)返回布尔值, source, global,ignoreCase,multiline,lastIndex
2. Client JavaScript
2.1 Browser
2.1.1 Browser Environment
2.1.1.1 Window object
2.1.1.2 DOM
self,window,parent,top;navigator;frames[];location;history;document;screen
document:forms[];anchors[];links[];images[];applets[];
forms[]:elements[]:options[]
2.1.1.3 event driven
2.1.2 embeded into HTML
2.1.2.1 <script></script>
2.1.2.2 <script type=”text/javascript”src=””></script>,
<metahttp-equiv=”Content-Script-Type” content=”text/javascript”>
2.1.2.3 defer attribute:延迟脚本执行,继续解析HTML文档
2.1.2.4 <noscript></noscript>
2.1.2.5 </script>:document.wirte(“<\/script>”),document.write(“</”+”script>”)
2.1.2.6 隐藏:<script type=”text/javascript” src=””><!--//--></script>
2.1.3 event handle
onclick,onmousedown,onmouseup,onmouseover,onmouseout,onchange,onload
2.1.4 url JavaScript
2.1.5 run JavaScript
2.1.6 compatibility:quirksmode.org/dom;webdevout.net/browser_support.php
2.1.6.1 功能测试
2.1.6.2 浏览器测试
2.1.6.3 IE条件测试
2.1.6.3.1 HTML
<!—[if IE]>
<![endif]-->
2.1.6.3.2 JavaScript
/*@cc_on
@if (@_jscript)
@else
@end
@*/
2.1.6.4 accesibility
2.1.6.5 security: ActiveXObject, XSS, DoS
2.2 Scripting Browser Window:BOM
2.2.1 Timer
setTimeout(),clearTimeout(), setInterval(), clearInterval()
2.2.2 Location & History
location.href,protocol,host,pathname,search
history.back(),forward(),go()
2.2.3 window, screen, browser
2.2.3.1 window: window.outerWidth,outHeight,screenX,screenY,innerWidth,innerHeight,pageXOffset,pageYOffset
2.2.4 Screen: width, height, availWidth,availHeight
2.2.5 Navigator: appName, appVersion,userAgent, appCodeName, platform
2.2.6 window operation
2.2.6.1 open: open()
2.2.6.2 close:close()
2.2.6.3 size:moveTo(),moveBy(),resizeTo(),resizeBy()
2.2.6.4 focus: focus(), blur()
2.2.6.5 scroll: scrollTo(), scrollBy(),offsetLeft, offsetTop, scrollIntoView()
2.2.7 dialog
alert(),prompt(), confirm()
2.2.8 status:status, defaultStatus
2.2.9 error: onerror()
2.2.10 multi window & frame
2.3 Scripting Document: DOM
2.3.1 document.write(),writeln()
2.3.2 document properties
2.3.2.1 bgColor
2.3.2.2 cookie
2.3.2.3 domain
2.3.2.4 lastModified
2.3.2.5 location
2.3.2.6 referrer
2.3.2.7 title
2.3.2.8 URL = location.href
2.3.3 遗留DOM collection
2.3.3.1 anchors[]
2.3.3.2 applets[]
2.3.3.3 forms[]: elements[]
2.3.3.4 images[]
2.3.3.5 links[]
2.3.4 W3C DOM
2.3.4.1 document tree
2.3.4.2 node
2.3.4.2.1 node type
interface | nodeType constraints | nodeType value |
Element | Node.ELEMENT_NODE | 1 |
Text | Node.TEXT_NODE | 3 |
Document | Node.DOCUMENT_NODE | 9 |
Comment | Node.COMMENT_NODE | 8 |
DocumentFragment | Node.DOCUMENT_FRAGMENT_NODE | 11 |
Attr | Node.ATTRIBUTE_NODE | 2 |
2.3.4.2.2 attribute: Element: getAttribute(),setAttribute(), removeAtrribute()
2.3.4.2.3 Node: Document, CharacterData,Element, Attr
Document:HTMLDocument
CharacterData:Text, Comment
Element:HTMLElement
HTMLElement:HTMLHeadElement, HTMLBodyElement, HTMLTitleElement, HTMLParagraphElement, HTMLInputElement,HTMLTableElement
2.3.4.2.4 Node: childNodes, firstChild,lastChild, nextSibling, previousSibling, parentNode
appendChild(),removeChild(), replaceChild(), insertBefore()
2.3.4.3 DOM HTML API
2.3.4.3.1HTMLElement: id, style, title, lang, dir, className
2.3.4.4 DOM Level & Feature: Level 0,1, 2, 3
2.3.5 document enumeration:
2.3.6 document search:getElementByTagName(), getElementById()
2.3.7 modify document: setAttribute()
2.3.8 add content:document.createElement(), createTextNode()
2.3.9 IE 4 DOM
2.4 CSS
2.5 Event
2.6 Form
2.7 Cookie
2.7.1 cookie: document.cookie, expires,max-age, path, domain, secure
2.7.2 storage: < 300/browser,<4KB/cookie, < 20/domain
2.7.3 substitute solution
2.7.3.1 IE userData
2.7.3.2 Flash SharedObject
2.8 XMLHttp
2.9 XML
2.10Canvas
2.11Applet & Flash
3.