<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 數據類型 WXS 語言目前共有以下幾種數據類型: - `number` : 數值 - `string` :字符串 - `boolean`:布爾值 - `object`:對象 - `function`:函數 - `array` : 數組 - `date`:日期 - `regexp`:正則 ## number ### 語法 number 包括兩種數值:整數,小數。 ``` var a = 10; var PI = 3.141592653589793; ``` ### 屬性 - `constructor`:返回字符串 `"Number"`。 ### 方法 - `toString` - `toLocaleString` - `valueOf` - `toFixed` - `toExponential` - `toPrecision` > 以上方法的具體使用請參考 `ES5` 標準。 ## string ### 語法 string 有兩種寫法: ``` 'hello world'; "hello world"; ``` ### 屬性 - `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` 標準。 ## boolean ### 語法 布爾值只有兩個特定的值:`true` 和 `false`。 ### 屬性 - `constructor`:返回字符串 `"Boolean"`。 ### 方法 - `toString` - `valueOf` > 以上方法的具體使用請參考 `ES5` 標準。 ## object ### 語法 object 是一種無序的鍵值對。使用方法如下所示: ``` 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); ``` ### 屬性 - `constructor`:返回字符串 `"Object"`。 ``` console.log("Object" === {k:"1",v:"2"}.constructor) ``` ### 方法 - `toString`:返回字符串 `"[object Object]"`。 ## function ### 語法 function 支持以下的定義方式: ``` //方法 1 function a (x) { return x; } //方法 2 var b = function (x) { return x; } ``` function 同時也支持以下的語法(匿名函數,閉包等): ``` var a = function (x) { return function () { return x;} } var b = a(100); console.log( 100 === b() ); ``` ### arguments function 里面可以使用 `arguments` 關鍵詞。該關鍵詞目前只支持以下的屬性: - `length`: 傳遞給函數的參數個數。 - `[index]`: 通過 `index` 下標可以遍歷傳遞給函數的每個參數。 **示例代碼:** ``` 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); ``` ### 屬性 - `constructor`:返回字符串 `"Function"`。 - `length`:返回函數的形參個數。 ### 方法 - `toString`:返回字符串 `"[function Function]"`。 **示例代碼:** ``` var func = function (a,b,c) { } console.log("Function" === func.constructor); console.log(3 === func.length); console.log("[function Function]" === func.toString()); ``` ## array ### 語法 array 支持以下的定義方式: ``` var a = []; //生成一個新的空數組 a = [1,"2",{},function(){}]; //生成一個新的非空數組,數組元素可以是任何類型 ``` ### 屬性 - `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`函數, 返回一個當前時間的對象。 ``` getDate() getDate(milliseconds) getDate(datestring) getDate(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]]) ``` - 參數 - `milliseconds`: 從1970年1月1日00:00:00 UTC開始計算的毫秒數 - `datestring`: 日期字符串,其格式為:"month day, year hours:minutes:seconds" **示例代碼:** ``` var date = getDate(); //返回當前時間對象 date = getDate(1500000000000); // Fri Jul 14 2017 10:40:00 GMT+0800 (中國標準時間) date = getDate('2017-7-14'); // Fri Jul 14 2017 00:00:00 GMT+0800 (中國標準時間) date = getDate(2017, 6, 14, 10, 40, 0, 0); // Fri Jul 14 2017 10:40:00 GMT+0800 (中國標準時間) ``` ### 屬性 - `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`函數。 ``` getRegExp(pattern[, flags]) ``` - 參數: - `pattern`: 正則表達式的內容。 - ``` flags ``` :修飾符。該字段只能包含以下字符: - `g`: global - `i`: ignoreCase - `m`: multiline。 **示例代碼:** ``` 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); ``` ### 屬性 - `constructor`:返回字符串 `"RegExp"`。 - `source` - `global` - `ignoreCase` - `multiline` - `lastIndex` > 除constructor外屬性的具體含義請參考 `ES5` 標準。 ### 方法 - `exec` - `test` - `toString` > 以上方法的具體使用請參考 `ES5` 標準。 ## 數據類型判斷 ### `constructor` 屬性 數據類型的判斷可以使用 `constructor` 屬性。 **示例代碼:** ``` 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` 使用 `typeof` 也可以區分部分數據類型。 **示例代碼:** ``` 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 ); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看