开发者社区
社区提问意见反馈
开发者钉组织
扫描二维码
加入支付宝开发者钉组织
native 渲染
性能与优化
小程序全局配置
小程序页面
axml
sjs 语法参考
事件系统
自定义组件
基础能力
基础库
基础库更新日志
开发 > 框架 > sjs 语法参考 > 数据类型
贡献者
收藏
订阅更新
我的文档
设置
sjs 目前支持如下数据类型:
string:字符串。
boolean:布尔值。
number:数值。
object:对象。
function:函数。
array:数组。
date:日期。
regexp:正则表达式。
判断数据类型
sjs 提供了 constructor 与 typeof 两种方式判断数据类型。
constructor
javascript
复制代码
const number = 10;
console.log(number.constructor); // "number"
const string = "str";
console.log(string.constructor); // "string"
const boolean = true;
console.log(boolean.constructor); // "boolean"
const object = {};
console.log(object.constructor); // "object"
const func = function(){};
console.log(func.constructor); // "function"
const array = [];
console.log(array.constructor); // "array"
const date = getdate();
console.log(date.constructor); // "date"
const regexp = getregexp();
console.log(regexp.constructor); // "regexp"
typeof
string
语法
es6 语法
属性
constructor:返回值 "string"
length
说明:constructor 属性外,其它属性的具体含义请参考 es5 标准。
方法
tostring
valueof
charat
charcodeat
concat
indexof
lastindexof
localecompare
match
replace
search
slice
split
substring
tolowercase
tolocalelowercase
touppercase
tolocaleuppercase
trim
说明: 具体使用请参考 es5 标准。
number
语法
属性
constructor:返回值  "number"
方法
tostring
tolocalestring
valueof
tofixed
toexponential
toprecision
说明: 具体使用请参考 es5 标准。
boolean
布尔值只有两个特定的值:true 和 false。
语法
属性
constructor:返回值"boolean"
方法
tostring
valueof
说明: 具体使用请参考 es5 标准。
object
语法
es6 语法
属性
constructor:返回值 "object"
方法
tostring:返回字符串 "[object object]"
function
语法
function 中可以使用 arguments 关键字。
输出:
属性
constructor:返回值 "function"
length:返回函数的形参个数。
方法
tostring:返回字符串 "[function function]"
示例
输出:
array
语法
属性
constructor:返回值 "array"
length
说明:constructor 属性外,其它属性的具体含义请参考 es5 标准。
方法
tostring
concat
join
pop
push
reverse
shift
slice
sort
splice
unshift
indexof
lastindexof
every
some
foreach
map
filter
reduce
reduceright
说明: 具体使用请参考 es5 标准。
date
语法
生成 date 对象需要使用 getdate 函数,返回一个当前时间的对象。
参数
milliseconds:从 1970年1月1日00:00:00 utc 开始计算的毫秒数。
datestring:日期字符串,其格式为  "month day, year hours:minutes:seconds"
属性
constructor:返回值"date"
方法
tostring
todatestring
totimestring
tolocalestring
tolocaledatestring
tolocaletimestring
valueof
gettime
getfullyear
getutcfullyear
getmonth
getutcmonth
getdate
getutcdate
getday
getutcday
gethours
getutchours
getminutes
getutcminutes
getseconds
getutcseconds
getmilliseconds
getutcmilliseconds
gettimezoneoffset
settime
setmilliseconds
setutcmilliseconds
setseconds
setutcseconds
setminutes
setutcminutes
sethours
setutchours
setdate
setutcdate
setmonth
setutcmonth
setfullyear
setutcfullyear
toutcstring
toisostring
tojson
说明: 具体使用请参考 es5 标准。
示例
regexp
语法
生成 regexp 对象需要使用 getregexp 函数。
参数
pattern: 正则的内容。
flags:修饰符,只能包括一下字符: gim
属性
constructor:返回字符串 "regexp"
global
ignorecase
lastindex
multiline
source
说明:除 constructor 属性外,其它属性的具体含义请参考 es5 标准。
方法
exec
test
tostring
说明:具体使用请参考 es5 标准。
示例
内容没有解决您的问题?您还可以前往 或 寻求帮助
凯发k8官方网娱乐官方 copyright © 2022 支付宝(杭州)信息技术有限公司  | icp证浙b2-20160559
该文档对你是否有帮助?
当前页面目录
网站地图