javascript && wxss
微信小程序运行在三端:iOS、Android 和 用于调试的开发者工具。
三端的脚本执行环境聚以及用于渲染非原生组件的环境是各不相同的:
-
在 iOS 上,小程序的 javascript 代码是运行在 JavaScriptCore 中,是由 WKWebView 来渲染的,环境有 iOS8、iOS9、iOS10
-
在 Android 上,小程序的 javascript 代码是通过 X5 JSCore来解析,是由 X5 基于 Mobile Chrome 37 内核来渲染的
-
在 开发工具上, 小程序的 javascript 代码是运行在 nwjs 中,是由 Chrome Webview 来渲染的
尽管三端的环境是十分相似的,但是还是有些许区别:
客户端可信域名校验
开发者使用手机扫码调试的场景下,打开调试模式之后,最新版的客户端将不检查可信域名。
代码文件必须 UTF8 编码
iOS下仅支持 UTF8 编码格式,最新版本的开发者工具会在上传代码时候对代码文件做一次编码格式校验。
ES6 APi 支持情况
微信小程序已经支持了绝大部分的 ES6 API 具体表格如下:
-
tip
: TBS 3.0 是指微信小程序 Android 运行环境
-
tip
: Array.values
不支持
-
tip
: Proxy
不支持
String |
iOS8 |
iOS9 |
iOS10 |
TBS3.0 |
codePointAt |
|
|
|
|
normalize |
|
|
|
|
includes |
|
|
|
|
startsWith |
|
|
|
|
endsWith |
|
|
|
|
repeat |
|
|
|
|
String.fromCodePoint |
|
|
|
|
Array |
iOS8 |
iOS9 |
iOS10 |
TBS3.0 |
copyWithin |
|
|
|
|
find |
|
|
|
|
findIndex |
|
|
|
|
fill |
|
|
|
|
entries |
|
|
|
|
keys |
|
|
|
|
values |
✘ |
|
|
✘ |
includes |
|
|
|
|
Array.from |
|
|
|
|
Array.of |
|
|
|
|
Number |
iOS8 |
iOS9 |
iOS10 |
TBS3.0 |
isFinite |
|
|
|
|
isNaN |
|
|
|
|
parseInt |
|
|
|
|
parseFloat |
|
|
|
|
isInteger |
|
|
|
|
EPSILON |
|
|
|
|
isSafeInteger |
|
|
|
|
Math |
iOS8 |
iOS9 |
iOS10 |
TBS3.0 |
trunc |
|
|
|
|
sign |
|
|
|
|
cbrt |
|
|
|
|
clz32 |
|
|
|
|
imul |
|
|
|
|
fround |
|
|
|
|
hypot |
|
|
|
|
expm1 |
|
|
|
|
log1p |
|
|
|
|
log10 |
|
|
|
|
log2 |
|
|
|
|
sinh |
|
|
|
|
cosh |
|
|
|
|
tanh |
|
|
|
|
asinh |
|
|
|
|
acosh |
|
|
|
|
atanh |
|
|
|
|
Object |
iOS8 |
iOS9 |
iOS10 |
TBS3.0 |
is |
|
|
|
|
assign |
|
|
|
|
getOwnPropertyDescriptor |
|
|
|
|
keys |
|
|
|
|
getOwnPropertyNames |
|
|
|
|
getOwnPropertySymbols |
|
|
|
|
Other |
iOS8 |
iOS9 |
iOS10 |
|
TBS3.0 |
Symbol |
|
|
|
|
|
Set |
|
|
|
|
|
Map |
|
|
|
|
|
Proxy |
✘ |
✘ |
|
✘ |
|
Reflect |
|
|
|
|
|
Promise |
|
|
|
|
|
更多
微信小程序开发教程,可以关注hi小程序。