# JavaScript Support
# Operational limitations
For security reasons, dynamic execution is not supported in Mini Programs JS Code, namely:
- Does not support the use of
eval
implement JS code - Does not support the use of
new Function
Create functionnew Function('return this')
Except
# standard ECMAScript Support
Mini Program. JS Implementation environment Different execution environments on different platforms, thus resulting in different platforms' interest in ECMAScript There are differences in support of standards.
The Mini Program base library in order to smooth out these differences as much as possible, built in a core-js
Polyfill。core-js
The missing criteria for the platform environment API Make up.
It is important to note that the platform for ECMAScript Syntax support differences cannot be smoothed out when you need to use some advanced syntax, such as async/await
When you need help. [Code Conversion Tool](https://developers.weixin.qq.com/miniprogram/dev/Devtools /codecompile.html#es6-%E8%BD%AC-es5) To support these grammars.
# Unable to be Polyfill of API
Following API Not available in some of the lower versions of the client, be careful to avoid using
Proxy
object
# Differences with standards
# Promise Timing difference
Because iOS JavaScriptCore Limitations, iOS 15 And the following Promise
Is one that uses the setTimeout
Analog Polyfill。Which means Promise
The triggered task is a normal task, not a micro-task, which results in in iOS15 And the following Promise
The timing will differ from the standard。
iOS 16 And above there is no difference.
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 (() => {
// Should be output [1,2,3,4,5,6,7]
// in iOS15 Mini Program environment, here will output [1,2,3,4,6,5,7]
console.log(arr)
}, 1000)
The difference between a normal task and a microtask can be viewedThis article
# How to determine what is needed in the current environment Polyfill & Code conversion target
Specific mini program base library versions have minimum WeChat client version requirements, such as base library v2.15.0 Minimum Android version required 7.0.22,iOS Minimum version 7.0.20。
Specific client versions have minimum operating system version requirements, such as iOS 7.0.20 Minimum requirements iOS 10。
Thus, when a specific Mini Program base library version is specified (which can be found in Mini Program management page [Settings] - [Basic Settings] - [Base Library Lowest Version Settings]), we are able to get the minimum required support for the execution environment.
Specific data can be obtained from [This open source library](https://github.com/WeChat mini-program /miniprogram-compact ) Obtained in.