# Data type
The WXS language currently has several data types:
Number: Numerical valueString: character stringBoolean: Boolean valueObject: Object objectFunction: function functionArray: array arrayDate: DateRegexp: Regexp
# number
# grammar
Number includes two values: integer and decimal.
var a = 10;
var PI = 3.141592653589793;
# attribute
Constructor: Returns the character string"Number"。
# method
toStringtoLocaleStringvalueOftoFixedtoExponentialtoPrecision
The specific use of the above methods refer to
ES5standard.
# string
# grammar
String can be written in two ways:
'hello world';
"hello world";
# attribute
Constructor: Returns the character string"String"。length
Refer to
ES5for the specific meaning of attributes other than constructor.
# method
toStringvalueOfcharAtcharCodeAtconcatindexOflastIndexOflocaleComparematchreplacesearchslicesplitsubstringtoLowerCasetoLocaleLowerCasetoUpperCasetoLocaleUpperCasetrim
The specific use of the above methods refer to
ES5standard.
# boolean
# grammar
Boolean values have only two specific values:trueandfalse.
# attribute
Constructor: Returns the character string"Boolean"。
# method
toStringvalueOf
The specific use of the above methods refer to
ES5standard.
# object
# grammar
Object is an unordered key-value pair. How to use it is as follows:
var o = {} //生成一个新的空对象
//生成一个新的非空对象
o = {
'string' : 1, //object 的 key 可以是字符串
const_var : 2, //object 的 key 也可以是符合变量定义规则的标识符
func : {}, //object 的 value 可以是任何类型
};
//对象属性的读操作
console.log(1 === o['string']);
console.log(2 === o.const_var);
//对象属性的写操作
o['string']++;
o['string'] += 10;
o.const_var++;
o.const_var += 10;
//对象属性的读操作
console.log(12 === o['string']);
console.log(13 === o.const_var);
# attribute
Constructor: Returns the character string"Object"。
console.log("Object" === {k:"1",v:"2"}.constructor)
# method
ToString: Returns the character string"[object Object]"。
# function
# grammar
Functions support the following definitions:
//方法 1
function a (x) {
return x;
}
//方法 2
var b = function (x) {
return x;
}
Functions also support the following syntax (anonymous functions, closures, etc.):
var a = function (x) {
return function () { return x;}
}
var b = a(100);
console.log( 100 === b() );
# arguments
Function can useargumentskeywords.The keyword currently supports only the following attributes:
Length: The number of arguments passed to a function.[index]: Each parameter passed to a function can be traversed through theindexindex.
Example code:
var a = function(){
console.log(3 === arguments.length);
console.log(100 === arguments[0]);
console.log(200 === arguments[1]);
console.log(300 === arguments[2]);
};
a(100,200,300);
# attribute
Constructor: Returns the character string"Function"。Length: Returns the number of parameters of the function.
# method
ToString: Returns the character string"[function Function]"。
Example code:
var func = function (a,b,c) { }
console.log("Function" === func.constructor);
console.log(3 === func.length);
console.log("[function Function]" === func.toString());
# array
# grammar
Array supports the following definitions:
var a = []; //生成一个新的空数组
a = [1,"2",{},function(){}]; //生成一个新的非空数组,数组元素可以是任何类型
# attribute
Constructor: Returns the character string"Array"。length
Refer to
ES5for the specific meaning of attributes other than constructor.
# method
toStringconcatjoinpoppushreverseshiftslicesortspliceunshiftindexOflastIndexOfeverysomeforEachmapfilterreducereduceRight
The specific use of the above methods refer to
ES5standard.
# date
# grammar
Generating a date object requires thegetDatefunction, which returns an object of the previous time.
getDate()
getDate(milliseconds)
getDate(datestring)
getDate(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]])
- parameter
Milliseconds: The number of milliseconds calculated from 000000000000UTC on January 1, 1970Datstring: The date character string in the form of:" month day, year hours:minutes:seconds "
Example code:
var date = getDate(); //返回当前时间对象
date = getDate(1500000000000);
// Fri Jul 14 2017 10: 40: 00 GMT + 0800 (China Standard Time)
date = getDate('2017-7-14');
// Fri Jul 14 2017 00: 00: 00 GMT + 0800 (China Standard Time)
date = getDate(2017, 6, 14, 10, 40, 0, 0);
// Fri Jul 14 2017 10: 40: 00 GMT + 0800 (China Standard Time)
# attribute
Constructor: Returns the character string "Date."
# method
toStringtoDateStringtoTimeStringtoLocaleStringtoLocaleDateStringtoLocaleTimeStringvalueOfgetTimegetFullYeargetUTCFullYeargetMonthgetUTCMonthgetDategetUTCDategetDaygetUTCDaygetHoursgetUTCHoursgetMinutesgetUTCMinutesgetSecondsgetUTCSecondsgetMillisecondsgetUTCMillisecondsgetTimezoneOffsetsetTimesetMillisecondssetUTCMillisecondssetSecondssetUTCSecondssetMinutessetUTCMinutessetHourssetUTCHourssetDatesetUTCDatesetMonthsetUTCMonthsetFullYearsetUTCFullYeartoUTCStringtoISOStringtoJSON
The specific use of the above methods refer to
ES5standard.
# regexp
# grammar
Generating the regexp object requires thegetRegExpfunction.
getRegExp(pattern[, flags])
- Parameters:
Pattern: The content of a regular expression.Flags: Modifiers.This field can only contain the following characters:g: globali: ignoreCasem: multiline。
Example code:
var a = getRegExp("x", "img");
console.log("x" === a.source);
console.log(true === a.global);
console.log(true === a.ignoreCase);
console.log(true === a.multiline);
# attribute
Constructor: Returns the character string"RegExp"。sourceglobalignoreCasemultilinelastIndex
Refer to
ES5for the specific meaning of attributes other than constructor.
# method
exectesttoString
The specific use of the above methods refer to
ES5standard.
# Data type judgment
# Constructor
The data type can be determined using the constructorproperty.
Example code:
var number = 10;
console.log( "Number" === number.constructor );
var string = "str";
console.log( "String" === string.constructor );
var boolean = true;
console.log( "Boolean" === boolean.constructor );
var object = {};
console.log( "Object" === object.constructor );
var func = function(){};
console.log( "Function" === func.constructor );
var array = [];
console.log( "Array" === array.constructor );
var date = getDate();
console.log( "Date" === date.constructor );
var regexp = getRegExp();
console.log( "RegExp" === regexp.constructor );
# typeof
Some data types can also be distinguished usingtypeof.
Example code:
var number = 10;
var boolean = true;
var object = {};
var func = function(){};
var array = [];
var date = getDate();
var regexp = getRegExp();
console.log( 'number' === typeof number );
console.log( 'boolean' === typeof boolean );
console.log( 'object' === typeof object );
console.log( 'function' === typeof func );
console.log( 'object' === typeof array );
console.log( 'object' === typeof date );
console.log( 'object' === typeof regexp );
console.log( 'undefined' === typeof undefined );
console.log( 'object' === typeof null );