The mini-program uses the third-party library Immutable. js instance for details, the mini-program immutable. js
Preface
Immutable JS provides an inert Sequence that allows efficient queue method chains, such as map and filter, without creating intermediate representatives. Immutable provides Sequence, Range, Repeat, Map, OrderedMap, Set, and a sparse Vector through the inert queue and hash ing.
The applet cannot directly use require ('immutable. js') for calling. You need to modify the downloaded immutable code before using it.
Cause Analysis
Immutable uses UMD modular specifications
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.Immutable = factory());}(this, function () { 'use strict';var SLICE$0 = Array.prototype.slice;....}));
The implementation of UMD is very simple. First, determine whether the Node. js (CommonJS) module specification is supported. If so, use the Node. js (CommonJS) method to load the module. Determine whether AMD is supported, and use AMD to load modules. If neither of the first two does exist, the module is published to the global environment.
Both exports and module must be defined to load modules in CommonJS. Through the test, the program running environment exports and module are not defined.
Solution
Modify the Immutable code, comment out the Export Statement of the original module, and usemodule.exports = factory()
Force Export
(function(global, factory) { /* typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.Immutable = factory()); */ module.exports = factory();}(this, function() {
Use Immutable. js
// Index. jsvar Immutable = require ('.. /.. /libs/immutable. modified. js '); // obtain the application instance var app = getApp (); Page ({onLoad: function () {// console. log ('onload'); var that = this; var lines = []; lines. push ("var map1 = Immutable. map ({a: 1, B: 2, c: 3}); "); var map1 = Immutable. map ({a: 1, B: 2, c: 3}); lines. push ("var map2 = map1.set ('B', 50);"); var map2 = map1.set ('B', 50); lines. push ("map1.get ('B');"); lines. push (map1.get ('B'); lines. push ("map2.get ('B');"); lines. push (map2.get ('B'); this. setData ({text: lines. join ('\ n ')})}})
Summary
The above is all about this article. I hope to help you in your study or work. If you have any questions, please leave a message.