data type
The WXS language currently has the following data types:
number:Number
String:string
boolean: boolean
Object: object
Function: function
Array:array
Date: date
regexp: regular
number
grammar
number consists of two numbers: integer and decimal.
var a = 10;var PI = 3.141592653589793;
attribute
constructor: Returns the string "Number".
Method
toString
toLocaleString
valueOf
toFixed
toExponential
toPrecision
Refer to the ES5 standard for the specific use of the above methods.
string
grammar
string has two ways of writing:
'hello world';"hello world";
attribute
constructor: Returns the string "String".
length
Refer to the ES5 standard for the specific meaning of attributes other than constructor.
Method
toString
valueOf
charAt
charCodeAt
concat
indexOf
lastIndexOf
localeCompare
match
replace
search
slice
split
substring
toLowerCase
toLocaleLowerCase
toUpperCase
toLocaleUpperCase
trim
Refer to the ES5 standard for the specific use of the above methods.
boolean
grammar
Boolean values have only two specific values: true and false.
attribute
constructor: Returns the string "Boolean".
Method
toString
valueOf
Refer to the ES5 standard for the specific use of the above methods.
object
grammar
An object is an unordered key-value pair.Use it as follows:
var o = {} //Generate a new empty object//Generate a new non-empty object o = {'string': 1, the key of //object can be a string const_var : 2, //The object's key can also be an identifier that conforms to the variable definition rules func : {}, //Object's value can be of any type}; //object attribute's read operation console.log(1 == o['string']);console.log(2 === o.const_var); object attribute's write operation o['string']+; o['string'] += 10; o.const_var++; o.const_var += 10;//Read operation console.log for object attributes (12 == o['string']);console.log(13 === o.const_var);
attribute
constructor: Returns the string "Object".
console.log("Object" === {k:"1",v:"2"}.constructor)
Method
toString: Returns the string'[object Object]'.
function
grammar
function supports the following definitions:
//Method 1function a(x) {return x; }//Method 2var b = function (x) { return x; }
function also supports the following syntax (anonymous functions, closures, and so on):
var a = function (x) { return function () { return x;} }var b = a(100);console.log( 100 === b() );
arguments
function can use arguments keyword.The keyword currently supports only the following properties:
length: The number of arguments passed to the function.
[index]: Each parameter passed to a function can be traversed by an index subscript.
Sample 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 string "Function".
length: Returns the number of formal parameters of a function.
Method
toString: Returns the string'[function Function]'.
Sample 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 = []; //Generate a new empty array a = [1,'2', {}, function (){}]; //Generate a new non-empty array whose elements can be of any type
attribute
constructor: Returns the string "Array".
length
Refer to the ES5 standard for the specific meaning of attributes other than constructor.
Method
toString
concat
join
pop
push
reverse
shift
slice
sort
splice
unshift
indexOf
lastIndexOf
every
some
forEach
map
filter
reduce
reduceRight
Refer to the ES5 standard for the specific use of the above methods.
date
grammar
Generating a date object requires using the getDate function to return an object at the current time.
getDate() getDate(milliseconds) getDate(datestring) getDate(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]])
parameter
Milliseconds: milliseconds from January 1, 1970, at 00:00:00 UTC
datestring: A date string in the format: "month day, year hours:minutes:seconds"
Sample code:
var date = getDate(); //Returns the current time object date = getDate (1500000 000 000); //Fri Jul 14 2017 10:40:00 GMT+0800 (China Standard Time) date = getDate('2017-7-14'); //Fri Jul 14 2017 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 string "Date".
Method
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
Refer to the ES5 standard for the specific use of the above methods.
regexp
grammar
The getRegExp function is required to generate regexp objects.
getRegExp(pattern[, flags])
Parameters:
g: global
i: ignoreCase
m: multiline.
pattern: The content of a regular expression.
flags: modifier.The field can only contain the following characters:
Sample 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 string "RegExp".
source
global
ignoreCase
multiline
lastIndex
Refer to the ES5 standard for the specific meaning of attributes other than constructor.
Method
exec
test
toString
Refer to the ES5 standard for the specific use of the above methods.
Data Type Judgment
constructor property
The constructor attribute can be used to determine the data type.
Sample 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
Partial data types can also be distinguished using typeof.
Sample 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 );