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

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.
主站蜘蛛池模板: 三河市| 攀枝花市| 抚松县| 承德县| 遂昌县| 神池县| 石柱| 驻马店市| 麻阳| 怀化市| 墨竹工卡县| 始兴县| 乌鲁木齐县| 洪泽县| 潍坊市| 扶余县| 洛南县| 葵青区| 东丰县| 丰顺县| 监利县| 侯马市| 长乐市| 延寿县| 璧山县| 新竹县| 临武县| 泊头市| 和平县| 手游| 龙游县| 芮城县| 渝北区| 江达县| 商城县| 尤溪县| 二连浩特市| 新和县| 阜宁县| 安泽县| 安新县|