# JavaScript support
# Operating restrictions
For security reasons, dynamic execution of JS code is not supported in Weixin Mini Program, i.e.:
- Executing JS code with
evalis not supported - Creating functions with
new Functionis not supportedNew Function ('return this')
# Standard ECMAScript support
The Weixin Mini Program JS execution environment The execution environments vary across platforms, leading to differences in support for the ECMAScript standard.
Weixin Mini Program To minimize these differences, the base library has a built-in core-jsPolyfill 。core-jscan complement standard APIs missing from the platform environment.
It should be noted that the platform's support for ECMAScript syntax differences can not be smoothed out, when you need to use some high-level syntax, such as async/await You need the transcoding tool to support these syntax.
# Cannot be used by Polyfill's API
The following API is not available in some of the lower versions of the Guest Account. Please be careful to avoid using
Proxyobject
# Differences with the Standards
# Promise timing difference
Due to the limitations of iOS JavaScript Core,Promisefor iOS 15 and below is a Polyfill usingsetTimeoutsimulation.That meansPromiseThe triggered task is a normal task, not a microtask, which results in ThePromise]]time sequences differ from the standard in iOS 15 and below.
There is no difference for iOS 16 and above.
var arr = []
setTimeout(() => arr.push(6), 0)
arr.push(1)
const p = new Promise(resolve => {
arr.push(2)
resolve()
})
arr.push(3)
p.then(() => arr.push(5))
arr.push(4)
setTimeout(() => arr.push(7), 0)
setTimeout(() => {
// 应该输出 [1,2,3,4,5,6,7]
// 在 iOS15 小程序环境,这里会输出 [1,2,3,4,6,5,7]
console.log(arr)
}, 1000)
See the article on the difference between normal tasks and micro tasks
# How to Determine Which Polyfill & Transcoding Targets Your Current Environment Needs
Certain Weixin Mini Program base library releases have minimum WeChat client version requirements, such as base library v2.15.0 requires minimum version 7.0.22 for Android and 7.0.20 for iOS.
Certain consumer versions have a minimum operating system version requirement, such as iOS 7.0.20 requiring a minimum of iOS 10.
Thus, when a specific Weixin Mini Program base library version is specified (you can The Mini Program management page Set in Settings - Basic Settings - Base Library Lowest Version Settings] to get the minimum execution environment we need to support.
Specific data can be obtained from the open source library .