Basic library Overview

The basic library works as a container for loading the mini-program framework. The basic library provides standard components and API interfaces required by the mini program framework.

Compatibility

The upgrade of the mini-program basic library in the minor or patch version brings new features and optimizations to the basic components, API interfaces, and runtime features. Developers can determine and ensure compatibility with lower versions by the following Check version number methods.

Check version number

The version number of the Mini Program basic library is represented by the major.minor.patch string pattern. The description page of components, APIs, or other development resources should include the minimum version number of the basic library for each functionality.

The current basic library version number can be obtained by using the my.SDKVersion JSAPI.

Take the following codes interpret how the dot delimiter (.) works in the major.minor.patch string pattern.

copy
/**
 * @param {string} v1
 * @param {string} v2
 * @returns {-1 | 0 | 1}
 */
function compareVersion(v1, v2) {
  var s1 = v1.split(".");
  var s2 = v2.split(".");
  var len = Math.max(s1.length, s2.length);

  for (let i = 0; i < len; i++) {
    var num1 = parseInt(s1[i] || "0");
    var num2 = parseInt(s2[i] || "0");

    if (num1 > num2) {
      return 1;
    } else if (num1 < num2) {
      return -1;
    }
  }

  return 0;
}

// v1 > v2 , return 1
1 === compareVersion("2.6.8", "1.24.10");

// v1 = v2,  return 0
0 === compareVersion("2.6", "2.6.0");

New features

Add API compatibility handling

For new APIs, refer to the following codes to determine whether the current base library supports the API.

copy
if (my.getLocation) {
    my.getLocation();
} else {
    my.alert({
       title: 'Tips',
       content: 'The current App version is too early to use this function. Please upgrade to the latest version'
    });
}