JavaScript:修订间差异
来自康健生活
| 第225行: | 第225行: | ||
=== document === | === document === | ||
==== constructor ==== | |||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
| [[/ | | [[/Document()|Document()]] | ||
|} | |||
==== properties ==== | |||
{| class="wikitable" | |||
|- | |||
| activeElement || <s>alinkColor</s> || <s>all</s> || <s>anchors</s> || <s>applets</s> || <s>bgColor</s> || body || characterSet | |||
|- | |||
| childElementCount || children || compatMode || contentType || currentScript || defaultView || designMode || dir | |||
|- | |||
| doctype || documentElement || documentURI || <s>domain</s> || embeds || <s>fgColor</s> || firstElementChild || forms | |||
|- | |||
| <s>fullscreen</s> || fullscreenElement || fullscreenEnabled || head || <s>height</s> || hidden || images || implementation | |||
|- | |||
| lastElementChild || lastModified || <s>lastStyleSheetSet</s> || <s>linkColor</s> || links || location || mozSyntheticDocument || <s>origin</s> | |||
|- | |||
| pictureInPictureElement || pictureInPictureEnabled || plugins || pointerLockElement || <s>preferredStyleSheetSet</s> || readyState || referrer || <s>rootElement</s> | |||
|- | |||
| scripts || scrollingElement || <s>selectedStyleSheetSet</s> || styleSheets || <s>styleSheetSets</s> || timeline || title || URL | |||
|- | |||
| visibilityState || <s>vlinkColor</s> || <s>width</s> || <s>xmlEncoding</s> || <s>xmlVersion</s> || || || | |||
|} | |||
==== methods ==== | |||
{| class="wikitable" | |||
|- | |||
| adoptNode() || append() || caretPositionFromPoint() || caretRangeFromPoint() || <s>clear()</s> || close() || createAttribute() || createAttributeNS() | |||
|- | |||
| createCDATASection() || createComment() || createDocumentFragment() || createElement() || createElementNS() || <s>createEntityReference()</s> || createEvent() || createExpression() | |||
|- | |||
| createNodeIterator() || createNSResolver() || createProcessingInstruction() || createRange() || createTextNode() || <s>createTouch()</s> || <s>createTouchList()</s> || createTreeWalker() | |||
|- | |||
| elementFromPoint() || elementsFromPoint() || <s>enableStyleSheetsForSet()</s> || evaluate() || <s>execCommand()</s> || exitFullscreen() || exitPictureInPicture() || exitPointerLock() | |||
|- | |||
| getAnimations() || getElementById() || getElementsByClassName() || getElementsByName() || getElementsByTagName() || getElementsByTagNameNS() || getSelection() || hasFocus() | |||
|- | |||
| hasStorageAccess() || importNode() || mozSetImageElement() || open() || prepend() || <s>queryCommandEnabled()</s> || <s>queryCommandSupported()</s> || querySelector() | |||
|- | |||
| querySelectorAll() || <s>registerElement()</s> || releaseCapture() || replaceChildren() || requestStorageAccess() || write() || writeln() || | |||
|} | |||
==== events ==== | |||
{| class="wikitable" | |||
|- | |||
| afterscriptexecute || animationcancel || animationend || animationiteration || animationstart || beforescriptexecute || copy || cut | |||
|- | |||
| DOMContentLoaded || drag || dragend || dragenter || dragleave || dragover || dragstart || drop | |||
|- | |||
| fullscreenchange || fullscreenerror || gotpointercapture || keydown || <s>keypress</s> || keyup || lostpointercapture || paste | |||
|- | |||
| pointercancel || pointerdown || pointerenter || pointerleave || pointerlockchange || pointerlockerror || pointermove || pointerout | |||
|- | |- | ||
| | | pointerover || pointerup || readystatechange || scroll || selectionchange || selectstart || touchcancel || touchend | ||
|- | |- | ||
| | | touchmove || touchstart || transitioncancel || transitionend || transitionrun || transitionstart || visibilitychange || wheel | ||
|} | |} | ||
==== body ==== | ==== body ==== | ||
{| class="wikitable" | {| class="wikitable" | ||
2022年5月25日 (三) 05:02的版本
简介
JavaScript 包括三个部分,即 ECMAScript、DOM 和 BOM。ECMAScript 是 JavaScript 的核心语法,DOM 是 HTML 和 XML 的应用程序 API 接口,控制文档结构,BOM 是浏览器对象模型。
Javascript 语言属于 Lambda 语言的一种。
保留字和关键字
需要完善。
保留字
| break | case | catch | continue | default | delete | do | else |
| finally | for | function | if | in | instanceof | new | return |
| switch | this | throw | try | typeof | var | void | while |
| with |
关键字
| abstract | boolean | byte | char | class | const | debugger | double |
| enum | export | extends | final | float | goto | implements | import |
| int | interface | long | native | package | private | protected | public |
| short | static | super | synchronized | throws | transient | volatile |
注释
块注释
/* */,来自于 PL/I(Programming Language One) 的语言。
安全性:如果被注释的内容含有正则表达式,也许会被破坏注释内容。
字面量
对象字面量
标识符
由字母、数字、下划线、美元符组成。
严格模式指令
| use strict | 示例 |
| use asm | 示例 |
| use stricter | 示例 |
| use babel | 示例 |
| any other strings like this in the prologue | 示例 |
数据类型
基本数据类型
基本数据类型(简单数据类型、原始数据类型、值类型)。
| Number | 示例 | 示例 |
| Null | 示例 | 示例 |
| String | 示例 | 示例 |
| Boolean | 示例 | 示例 |
| Undefined | 示例 | 示例 |
| symbol | 示例 | 示例 |
| bigint | ||
| function |
复杂数据类型
复杂数据类型(对象类型、引用类型)。
| Object | object | 狭义的对象 |
|---|---|---|
| array | 数组 | |
| function | 函数 | |
| RegExp | ||
| Date |
判断方法
判断数据类型的三种方法
| typeof 运算符 | 使用广泛但不精确 |
| instanceof 运算符 | 示例 |
| constructor | |
| Object.prototype.toString 方法 | 示例 |
问题
| 原始类型与对象类型 |
运算
逻辑判断使用 == 而不是 ===
移位运算符
| 左位移 | 右位移 |
平方
实现
| ECMAScript | 语言核心 | 科学计数法 | polyfill |
| BOM | 浏览器对象模型 | 浮点数 | 反应路由器 |
| DOM | 文档对象模型 | 特殊的 Number 值 | 获取元素 |
语法
| 语句 | 注释 | 标识符 | 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 | 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 | 示例 | 示例 | 示例 |
函数
JavaScript 的函数主要基于词法作用域(lexical scoping),并且函数是顶级对象。
arguments
常用函数
| 防抖 | 节流 | 函数重载 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
| replace | postMessage | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
JavaScript
内存
| 栈内存(stack) | 堆内存(heap) | 池 | Buffer(堆外内存) |
对象
无类型
无类型对象系统(class-free)。
全局对象
全局对象(the globar object)
other
| canvas | console | instanceof | Promise | XSRF | constructor | Object.prototype.tostring.call | setTimeout | setimmediate |
| throw | while | Infinity | Object.defineProperty | Object.freeze | apply | Proxy | indexOf | |
| valueOf | map | Error | 示例 | 示例 | 示例 | 示例 | 示例 |
window
navigator
| userAgent | 示例 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
document
constructor
| Document() |
properties
| activeElement | body | characterSet | |||||
| childElementCount | children | compatMode | contentType | currentScript | defaultView | designMode | dir |
| doctype | documentElement | documentURI | embeds | firstElementChild | forms | ||
| fullscreenElement | fullscreenEnabled | head | hidden | images | implementation | ||
| lastElementChild | lastModified | links | location | mozSyntheticDocument | |||
| pictureInPictureElement | pictureInPictureEnabled | plugins | pointerLockElement | readyState | referrer | ||
| scripts | scrollingElement | styleSheets | timeline | title | URL | ||
| visibilityState |
methods
| adoptNode() | append() | caretPositionFromPoint() | caretRangeFromPoint() | close() | createAttribute() | createAttributeNS() | |
| createCDATASection() | createComment() | createDocumentFragment() | createElement() | createElementNS() | createEvent() | createExpression() | |
| createNodeIterator() | createNSResolver() | createProcessingInstruction() | createRange() | createTextNode() | createTreeWalker() | ||
| elementFromPoint() | elementsFromPoint() | evaluate() | exitFullscreen() | exitPictureInPicture() | exitPointerLock() | ||
| getAnimations() | getElementById() | getElementsByClassName() | getElementsByName() | getElementsByTagName() | getElementsByTagNameNS() | getSelection() | hasFocus() |
| hasStorageAccess() | importNode() | mozSetImageElement() | open() | prepend() | querySelector() | ||
| querySelectorAll() | releaseCapture() | replaceChildren() | requestStorageAccess() | write() | writeln() |
events
| afterscriptexecute | animationcancel | animationend | animationiteration | animationstart | beforescriptexecute | copy | cut |
| DOMContentLoaded | drag | dragend | dragenter | dragleave | dragover | dragstart | drop |
| fullscreenchange | fullscreenerror | gotpointercapture | keydown | keyup | lostpointercapture | paste | |
| pointercancel | pointerdown | pointerenter | pointerleave | pointerlockchange | pointerlockerror | pointermove | pointerout |
| pointerover | pointerup | readystatechange | scroll | selectionchange | selectstart | touchcancel | touchend |
| touchmove | touchstart | transitioncancel | transitionend | transitionrun | transitionstart | visibilitychange | wheel |
body
| replaceChild | firstElementChild | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
定义声明
| var | let | const | class | static | yield | Symbol | import |
Javascript 引擎(解析器)
| JavaScriptCore(JSCore) | Safari |
| JaegerMonkey | Mozilla |
| Chakra | IE/Edge |
| V8 | Chrome/Node.js |
| Carakan | Opera |
技巧
| 值交换 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
教程
兼容
错误处理
语句
循环语句
| while | switch | for |
文件
浏览器
| createReader | 长宽 | 示例 |
平台
判断
| 判断字符串 | 判断数字 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
事件
事件类型
DOM 3 级事件。
| 标题文字 | 标题文字 | 标题文字 | |||||
|---|---|---|---|---|---|---|---|
| UI 事件 | load | unload | abort | error | select | resize | scroll |
| 焦点事件 | focus | focusin | focusout | DOMFocusIn | DOMFocusOut | blur | |
| 鼠标事件 | click | dbclick | mousedown | mouseup | mouseover | mousemove | mousewheel |
| 滚轮事件 | 示例 | 示例 | |||||
| 文本事件 | keydown | keyup | keypress | textInput | |||
| 键盘事件 | 示例 | 示例 | |||||
| 合成事件 | 示例 | 示例 | |||||
| 变动事件 | 示例 | 示例 | |||||
| 变动名称事件 | 示例 | 示例 |
| 事件 | 默认行为 | 事件冒泡 | 事件捕获 | 事件委托 | 合成事件 |
| wheel | pointer | addEventListener | dispatchEvent | drag |
位置相关
| elementFromPoint | 元素位置 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
实例
| UUID | GUID | 加密解密 | url |
| 设备指纹 | 帆布指纹 | 指针 | 暂存死区 |
| 传参 | 数字与字符串 | 数组与字符串 | 尾递归 |
关键词
| 跨域 | 迭代器 | 事件循环 | macroTask | 匿名函数 | continue | 属性描述符 | 哑变量 | attribute |
| 拷贝 | 渐进式更新 | 进制 | 作用域(scope) | 模板渲染 | break | delete | 伪变量 | createDocumentFragment |
| 格式转换 | 闭包(Closure) | super | 引用(Reference) | 回调函数 | return | 逃逸分析 | 内存泄露 | 正则 |
| 变量提升 | 解构 | sleep | delay | * | new.target | 连续赋值 | 构造函数 | global |
| Copy-on-write | 立即函数 | 封装 | isNaN | websocket | Hook | 节点 | 简单算法 | 链式操作 |
| this | call bind apply | 隐式转换 | 微任务、宏任务 | 多重赋值 | 循环遍历 | mouse | 按键 | 随机 |
| 扩展运算符 | 假值(falsy) |
勘误
| const、var、let | 示例 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
代码库
| URI.js | Falsy | vue.js | Cheerio | Express | Koa | Electron | axios | typescript | Prettier | Mockjs |
| jquery | react | thinkjs |
请求
| axios | fetch |
Web API
| CustomEvent | HTMLButtonElement | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
存储
| cookie | 示例 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
场景
| 寻径 | 画布 | 页面引导 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
参考
其他
| 刷新页面 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
工具
| Fundebug |
练习题
| 青蛙跳台阶 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
Version history
| Version | Release date | Equivalent to | Netscape Navigator |
Mozilla Firefox |
Internet Explorer |
Opera | Safari | Google Chrome |
|---|---|---|---|---|---|---|---|---|
| 1.0 | March 1996 | 2.0 | 3.0 | |||||
| 1.1 | August 1996 | 3.0 | ||||||
| 1.2 | June 1997 | 4.0-4.05 | 3 | |||||
| 1.3 | October 1998 | ECMA-262 1st + 2nd edition | 4.06-4.7x | 4.0 | 5 | |||
| 1.4 | Netscape Server |
6 | ||||||
| 1.5 | November 2000 | ECMA-262 3rd edition | 6.0 | 1.0 | 5.5 (JScript 5.5), 6 (JScript 5.6), 7 (JScript 5.7), 8 (JScript 5.8) |
7.0 | 3.0-5 | 1.0-10.0.666 |
| 1.6 | November 2005 | 1.5 + array extras + array and string generics + E4X | 1.5 | |||||
| 1.7 | October 2006 | 1.6 + Pythonic generators + iterators + let | 2.0 | 28.0.1500.95 | ||||
| 1.8 | June 2008 | 1.7 + generator expressions + expression closures | 3.0 | 11.50 | ||||
| 1.8.1 | 1.8 + native JSON support + minor updates | 3.5 | ||||||
| 1.8.2 | June 22, 2009 | 1.8.1 + minor updates | 3.6 | |||||
| 1.8.5 | July 27, 2010 | 1.8.2 + new features for ECMA-262 5th edition compliance | 4.0 |
No categories