官术网_书友最值得收藏!

Using the stack

To use the Stack class created previously, you would have to make a minor change to allow the stack to be used based on the environment in which you are planning to use it. Making this change generic is fairly straightforward; that way, you do not need to worry about multiple environments to support and can avoid repetitive code in each application:

// AMD
if (typeof define === 'function' && define.amd) {

define(function () { return Stack; });

// NodeJS/CommonJS

} else if (typeof exports === 'object') {

if (typeof module === 'object' && typeof module.exports ===
'object') {

exports = module.exports = Stack;
}

// Browser

} else {

window.Stack = Stack;
}

Once we add this logic to the stack, it is multi-environment ready. For the purpose of simplicity and brevity, we will not add it everywhere we see the stack; however, in general, it's a good thing to have in your code.

If your technology stack comprises ES5, then you need to transpile the preceding stack code to ES5. This is not a problem, as there are a plethora of options available online to transpile code from ES6 to ES5.
主站蜘蛛池模板: 河曲县| 阳西县| 兴国县| 松溪县| 泸溪县| 定边县| 辽中县| 青浦区| 衡东县| 蒙山县| 陆良县| 盘山县| 清原| 郁南县| 平南县| 龙游县| 南部县| 开平市| 汝城县| 秦皇岛市| 丹凤县| 蒙阴县| 皮山县| 永康市| 萨迦县| 漯河市| 屏南县| 博野县| 刚察县| 平度市| 正蓝旗| 县级市| 扎兰屯市| 车致| 突泉县| 北川| 基隆市| 泽州县| 青神县| 泌阳县| 偏关县|