JavaScript 函數、序列化/evel 時間複習

來源:互聯網
上載者:User

標籤:技術   搜尋   color   image   運算式   執行   ret   evel   表達   

函數分類:

script>    普通函數    function () {    }    匿名函數:    function func(arg){        return arg+1    }    setInterval(function(){console.log(123);},5000)    自執行函數:    function func () {}    func():    ==自動執行案例===    (function(arg){console.log(arg+1);})(123)    arg=形參,   後面括弧123是實參  傳入的數值</script>

 

1、序列化

  • JSON.stringify(obj)   序列化  將對象轉化成字串
  • JSON.parse(str)        還原序列化

 

2、轉義

  • decodeURI( )                   URl中未轉義的字元
  • decodeURIComponent( )   URI組件中的未逸出字元
  • encodeURI( )                   URI中的逸出字元
  • encodeURIComponent( )   轉義URI組件中的字元
  • escape( )                         對字串轉義
  • unescape( )                     給逸出字元串解碼
  • URIError                         由URl的編碼和解碼方法拋出
url="https://www.sogou.com/web?query=搜尋"encodeURI(url) //將中文字編碼"https://www.sogou.com/web?query=%E6%90%9C%E7%B4%A2"decodeURI(newurl)//將編碼進行解碼"https://www.sogou.com/web?query=搜尋"encodeURIComponent(url,newurl)//對專意字元=  %等符號進行編碼"https%3A%2F%2Fwww.sogou.com%2Fweb%3Fquery%3D%E6%90%9C%E7%B4%A2"    }

3、eval

JavaScript中的eval是Python中eval和exec的合集,既可以編譯代碼也可以擷取傳回值。

  • eval() 
  • EvalError   執行字串中的JavaScript代碼
evel
python
var=evel("1+1") 得到數值 2
exec(執行代碼) 沒有傳回值
JavaScript:
eval
可以是運算式 也可以是代碼

時間操作
Date類
var d= new Date()
d.getxxxx 擷取目前時間
d.setxxx 設定時間

JavaScript 函數、序列化/evel 時間複習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.