注:以下部分代码或术语涉及ECMAScript 6。

1. literal

literal(字面量)即开发者写的,可直接被解析器识别,不必显式依赖API创建的量。如:

  • 数字literal:123, 0b1111011, 0o173, 0x7B
  • 字符串literal:"123", `12{2+1}`
  • 数组literal:[1,2,8]
  • 对象literal:{A:1,B:2,C:8}
  • 正则表达式literal:/^\d+(?:\.\d+)?$/
  • 其他literal:true, false, null

2. IIFE

还记得为了闭包(closure)而编写的声明即执行的函数表达式吗?这种函数表达式是IIFE,读作[iffy]。

var chars=//charCode为0x20,0x21,...,0x7F的一组字符组成的字符串,由以下IIFE表示
(function(){var a=[];for(let i=0x20;i<0x80;i++){a.push(i);}return String.fromCharCode.apply(String,a);
})();

3. property and expando

property对于一般JavaScript开发者来说,熟悉而又陌生:
一个object的property含property key和property descriptor两部分。
property key分string和symbol两种。
property descriptor分data descriptor和accessor descriptor两种。
data descriptor有固定的value,而accessor descriptor有getter与/或setter。
property descriptor中的enumerable,configurable分别表示property是否可枚举,是否可重定义。

expando是property的一个形容词,指在规范之外扩展的,仅供实现者内部使用的。
对于jQuery而言,jQuery.fn属性可算作一个expando property。

举例:

var lengthExpando=Symbol.for("length");
function ArrayLike(){var length=0;// ...Object.defineProperty(this,lengthExpando,// symbol as a property key{enumerable:false,configurable:true,value:length}// data descriptor);// define an expando propertyObject.defineProperty(this,"length",// string as a property key{enumerable:false,configurable:true,get:function(){return this[lengthExpando];},set:function(value){var num=+value;var len=num>>>0;if(len!=num){throw new RangeError("Invalid length");}// ...this[lengthExpando]=len;}}// accessor descriptor);// define a spec-defined property
}

4. mixin

与plugin可被安装到兼容的宿主程序的概念类似,mixin是一个class/object,它的属性/方法可动态复制到其他适配的class/object。
举例:

// define a mixin which is compatible with any Array-like class or object
var ArrayLikePrototype={get firstElement(){var index=0;if(index<this.length){return this[index];}//return undefined;},getFirstElement(){var index=0;if(index<this.length){return this[index];}//return undefined;},get lastElement(){var index=this.length-1;if(index>-1){return this[index];}//return undefined;},getLastElement(){var index=this.length-1;if(index>-1){return this[index];}//return undefined;},// ...
};// mix `ArrayLikePrototype` in `NodeList.prototype`
Object.defineProperties(NodeList.prototype,Object.getOwnPropertyDescriptors(ArrayLikePrototype));// mix `ArrayLikePrototype` in `HTMLCollection.prototype`
Object.defineProperties(HTMLCollection.prototype,Object.getOwnPropertyDescriptors(ArrayLikePrototype));
//so that `document.children.firstElement` will be document.children[0]// or even mix `ArrayLikePrototype` in `Array.prototype`
Object.defineProperties(Array.prototype,Object.getOwnPropertyDescriptors(ArrayLikePrototype));
//so that `[1,2,3].lastElement` will be 3, and `[1,2,3].getLastElement()` will be 3 too

5. shim and polyfill

shim 是为修正运行环境API而编写的代码。如:

// shim Window#setTimeout()
if(document.documentMode==9&&!Object.prototype.hasOwnProperty.call(window,"setTimeout")){var WindowSetTimeout=Window.prototype.setTimeout;Window.prototype.setTimeout=function setTimeout(callback, delay){if(arguments.length<3||typeof callback!="function")return WindowSetTimeout.call(this, callback, delay);var args=Array.prototype.slice.call(arguments, 2);return WindowSetTimeout.call(this, function(){callback.apply(this, args);}, delay);};
}//shim window.Event
if(document.documentMode>8&&typeof window.Event=="object"){var nativeEvent=window.Event;var shimedEvent=function Event(type/*,eventInit*/){if(!(this instanceof Event))throw new TypeError("Failed to construct 'Event': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");if(arguments.length===0)throw new TypeError("Failed to construct 'Event': An event type must be provided.");var event=document.createEvent("Event"),eventInit={bubbles:false,cancelable:false},p=Object.assign(eventInit,arguments[1]);event.initEvent(type,p.bubbles,p.cancelable);return event;};shimedEvent.prototype=nativeEvent.prototype;window.Event=shimedEvent;
}

polyfill是为填补运行环境缺失的功能而提供的变通实现代码。如:

// polyfill Object.assign()
if(typeof Object.assign!="function"){Object.assign=function assign(object,source){var to,from,sources,nextSource,i,j,len,keys,key;//#1if(object==null)throw new TypeError("Cannot convert "+object+" to Object");to=Object(object);//#3if(arguments.length===1)return to;//#4sources=Array.prototype.slice.call(arguments,1);//#5for(i=0; i<sources.length; i++){//#anextSource=sources[i];if(nextSource==null){continue;}//#bfrom=Object(nextSource);//#dkeys=Object.keys(from);//#elen=keys.length;//#ffor(j=0;j<len;j++){key=keys[j];to[key]=from[key];}}//#6return to;};
}
// polyfill HTMLElement#hidden
if(typeof document.documentElement.hidden!="boolean"){Object.defineProperty(HTMLElement.prototype,"hidden",{get:function getHidden(){return this.getAttribute("hidden")!=null;},set:function setHidden(v){if(v)this.setAttribute("hidden", "");elsethis.removeAttribute("hidden");}});
}

6. SemVer

越扯越远,这一条似乎与JavaScript不相关。

平时我们看到的一些软件库文件名如jquery-2.1.3.js,知道其中的版本号2.1.3遵循X.Y.Z,但XYZ每部分的含义,升级规则和比较/排序规则却又不清楚。
为了定义一个通用的版本号标准,GitHub联合创始人Tom Preston-Werner编写了SemVer(Semantic Versioning)规范。
SemVer 2.0.0规范定义的版本号的格式如下:
major . minor . patch [ - pre] [ + build]
一个SemVer版本号不仅仅代表着一个独特的版本,还牵涉到其背后一系列的排序/升级/关联/筛选规则。

7. vanilla

这里的vanilla指寻常的,无特色的。vanilla js用中文说即纯手工编写,未用到第三方框架的js。

VanillaJS是一个没有可运行代码的JavaScript框架,通常被用作愚人节玩笑。它列举一些直接调用原生API而不必借助框架的实践方式,并突出这些寻常代码相对基于框架调用的代码所带来的性能优势,其思想有种道家无为的意味。但恰恰其他框架在试图证明使用框架后相对VanillaJS所带来的兼容/易用优势。

to be continued

更多见 MDN词汇表

一般人不清楚的JavaScript概念相关推荐

  1. javascript核心_只需几分钟即可学习这些核心JavaScript概念

    javascript核心 Sometimes, you just want to learn something quickly. And reading through comprehensive ...

  2. 36 个助你成为专家需要掌握的 JavaScript 概念

    code小生 一个专注大前端领域的技术平台 公众号回复Android加入安卓技术群 英文 | https://medium.com/better-programming/36-javascript-c ...

  3. 36个助你成为专家需要掌握的JavaScript概念

    英文 | https://medium.com/better-programming/36-javascript-concepts-you-need-to-master-to-become-an-ex ...

  4. [JavaWeb-JavaScript]JavaScript概念与功能

    JavaScript: * 概念: 一门客户端脚本语言* 运行在客户端浏览器中的.每一个浏览器都有JavaScript的解析引擎* 脚本语言:不需要编译,直接就可以被浏览器解析执行了* 功能:* 可以 ...

  5. JavaScript概念梳理

    一.JavaScript 的奇葩命名史 1995 年,网景浏览器(Netscape Navigator)首次发布了一种运行于浏览器端的脚本语言,网景给这个新语言命名为 LiveScript.一年后,为 ...

  6. 每个 JavaScript 工程师都应懂的33个概念

    简介 这个项目是为了帮助开发者掌握 JavaScript 概念而创立的.它不是必备,但在未来学习(JavaScript)中,可以作为一篇指南. 本篇文章是参照 @leonardomso 创立,英文版项 ...

  7. 了解这12个概念,让你的JavaScript水平更上一层楼

    JavaScript是一门复杂的语言.如果你是一名JavaScript开发人员,不管处于什么样的水平,都有必要了解JavaScript的基本概念.本文介绍了12个非常重要的JavaScript概念,但 ...

  8. JavaScript开发者应懂的33个概念

    JavaScript开发者应懂的33个概念 简介 这个项目是为了帮助开发者掌握 JavaScript 概念而创立的.它不是必备,但在未来学习(JavaScript)中,可以作为一篇指南. 本篇文章是参 ...

  9. 【转】JavaScript开发者应懂的33个概念

    JavaScript开发者应懂的33个概念 简介 这个项目是为了帮助开发者掌握 JavaScript 概念而创立的.它不是必备,但在未来学习(JavaScript)中,可以作为一篇指南. 本篇文章是参 ...

最新文章

  1. golang的mahonia字符集转换工具用法
  2. kotlin学习笔记——委托属性
  3. 二叉树的建立与三种遍历
  4. 程序员面试金典 - 面试题 04.03. 特定深度节点链表(BFS)
  5. 【操作系统复习】操作系统的概念、功能和目标
  6. 给GridView设置行高
  7. 闲谈输入法、MinGW、日文字体
  8. 广数980td系列2级密码及相关操作
  9. iphone6 计算机无法检测到照相机,爱思助手无法识别设备怎么办 爱思助手无法识别设备解决方法...
  10. Win7如何显示文件扩展名
  11. 云班课python答案_云班课测试题答案公众号
  12. Android自定义view-电子签名画板
  13. base64编码和解码的js工具函数
  14. 【第39题】位与 的应用 | 一句话消除末尾连续的 1
  15. MyBatis-Plus的条件查询(只举例部分方便使用)
  16. 平面设计师资格证怎么考
  17. 电信光纤猫HG8245 超级密码 及路由功能启用
  18. 年会模板汇总:PPT、策划案、游戏节目、流程、邀请函、背景音乐、主题词
  19. Linux mount挂载命令
  20. 海康萤石NTP时间不同步问题思路X5C

热门文章

  1. 机器人大冒险(二维数组)
  2. Mysql 多表联合更新
  3. TestLink1.6.0安装说明
  4. 产品版本、软件版本、文档版本定义
  5. 密码爆破工具————Medusa(美杜莎)介绍
  6. vite打包快几款基于vue3和vite的开箱即用的中后台管理模版
  7. GPS 校验和 代码_PSPad editor(代码编辑器)v5.0.4.507绿色版
  8. python积木编程软件_童心制物慧编程全新 Python 编辑器正式上线
  9. python小数点处理_如何在python中打小数点
  10. 小波变换的前因后果(三)