- JavaScript:Moving to ES2015
- Ved Antani Simon Timms Narayan Prusty
- 197字
- 2021-07-09 19:07:40
Shims or polyfills
Polyfills (also known as shims) are patterns to define behavior from a new version in a compatible form supported by an older version of the environment. There's a great collection of ES6 shims called ES6 shim (https://github.com/paulmillr/es6-shim/); I would highly recommend a study of these shims. From the ES6 shim collection, consider the following example of a shim.
The Number.isFinite()
method of the ECMAScript 2015 (ES6) standard determines whether the passed value is a finite number. The equivalent shim for it would look something as follows:
var numberIsFinite = Number.isFinite || function isFinite(value) { return typeof value === 'number' && globalIsFinite(value); };
The shim first checks if the Number.isFinite()
method is available; if not, it fills it up with an implementation. This is a pretty nifty technique to fill in gaps in specifications. Shims are constantly upgraded with newer features and, hence, it is a sound strategy to keep the most updated shims in your project.
Note
The endsWith()
polyfill is described in detail at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith. String.endsWith()
is part of ES6 but can be polyfilled easily for pre-ES6 environments.
Shims, however, cannot polyfill syntactical changes. For this, we can consider transpilers as an option.
- 潮流:UI設(shè)計(jì)必修課
- 信息可視化的藝術(shù):信息可視化在英國(guó)
- Java高手真經(jīng)(高級(jí)編程卷):Java Web高級(jí)開(kāi)發(fā)技術(shù)
- Java開(kāi)發(fā)入行真功夫
- 人人都是網(wǎng)站分析師:從分析師的視角理解網(wǎng)站和解讀數(shù)據(jù)
- PLC編程及應(yīng)用實(shí)戰(zhàn)
- SSM輕量級(jí)框架應(yīng)用實(shí)戰(zhàn)
- 精通MATLAB(第3版)
- C語(yǔ)言程序設(shè)計(jì)
- .NET 3.5編程
- Photoshop智能手機(jī)APP界面設(shè)計(jì)
- C#面向?qū)ο蟪绦蛟O(shè)計(jì)(第2版)
- SSH框架企業(yè)級(jí)應(yīng)用實(shí)戰(zhàn)
- Android開(kāi)發(fā)權(quán)威指南(第二版)
- Eclipse開(kāi)發(fā)(學(xué)習(xí)筆記)