語法練習
- 入門教學文件: W3School: JavaScript Tutorial
- 安裝並執行簡單的命令列版 js 解譯器:
apt-get install spidermonkey-bin。 以下指令皆在 js 解譯器內使用。 (1/5+3)*2- 數學函數:
Math.pow(Math.sin(Math.PI/3),2)詳 - 字串處理:
("refresh".substr(2,3) + "bleeding".substring(3,4)).toUpperCase()詳 - (多維) 陣列:
x = [['a','b','c'],['d'],['e','f','g','h']]; print(x[2][1], x[0].length)(用 "javascript ragged array" 好像找不到比較簡單清楚的資料; 看來是我的例子最簡單明瞭了) 注意: 這個 print 是 js 解譯器特有的函數, 這裡只是用它來練習; 真正的 javascript 裡面, 沒有地方讓你 print, 而是用 document.write() 之類的方式輸出。 - regexp 比對:
"break the sentence into words".match(/(\w+)/g)[3]、 regexp 代換:"break the sentence into words".replace(/(\w+)/g, "[$1]")、 線上測試 - Associative array 並不是陣列, 而是普通的物件: 1, 2, 3; 要查詢有多少對 key-value 有點麻煩。
另外, 有很多 frameworks 幫 javascript 擴充功能。 詳見 五個常用 frameworks 的比較, 及 jquery vs mootools 的比較。 後者比較適合中高階程式設計師; 前者適合想要快速上手者。
- 本頁最新版網址: http://people.ofset.org/~ckhung/b/js/syntax.php; 您所看到的版本: February 14 2012 10:32:25.
- 作者: 朝陽科技大學 資訊管理系 洪朝貴
- 寶貝你我的地球, 請 減少列印, 多用背面, 丟棄時做垃圾分類。
- 本文件以 Creative Commons Attribution-ShareAlike License 或以 Free Document License 方式公開授權大眾自由複製/修改/散佈。
![[rss feed 圖案]](/~ckhung//i/rss.png)
![[拒絕冏性升級 docx]](/~ckhung//i/n7/no-docx.png)
![[用創意換取注意力: 認識 CC 授權]](/~ckhung//i/cc.png)
![[(力求維持) 符合 xhtml 1.0]](/~ckhung//i/vxhtml10.png)
