Ajax與系列精華Javascript庫(Modello)
聲明:以下推薦的類均來自互聯(lián)網(wǎng)的開源項目,版權(quán)所有屬于原作者。
引用
使用Modello編寫JavaScript類
到目前為止,JavaScript 是一種不完全支持面向?qū)ο筇匦缘哪_本語言。之所以這樣說是因為 JavaScript 的確支持對象的概念,在程序中我們看到都是對象,可是 Javascipt 并不支持類的封裝和繼承。JavaScript 的確支持自定義對象和繼承,不過使用的是另外一種方式:prototype(中文譯作:原型)。用過 JavaScript 的或者讀過《設(shè)計模式》的讀者都會了解這種技術(shù),描述如下:
每個對象都包含一個 prototype 對象,當向?qū)ο蟛樵円粋€屬性或者請求一個方法的時候,運行環(huán)境會先在當前對象中查找,如果查找失敗則查找其 prototype 對象。注意 prototype 也是一個對象,于是這種查找過程同樣適用在對象的 prototype 對象中,直到當前對象的 prototpye 為空。
在 JavaScript 中,對象的 prototype 在運行期是不可見的,只能在定義對象的構(gòu)造函數(shù)時,創(chuàng)建對象之前設(shè)定。
使用 Modello 編寫的類所具備如下特性:
·私有成員、公共成員和靜態(tài)成員
·類的繼承,多繼承
·命名空間
·類型鑒別
Modello 還具有以下特性:
·更少的概念,更方便的使用方法
·小巧,只有兩百行左右的代碼
·設(shè)計期和運行期徹底分離,使用繼承的時候不需要使用 prototype,也不需要先創(chuàng)建父類的實例
·兼容 prototype.js 的類,兼容 JavaScript 構(gòu)造函數(shù)
·跨瀏覽器,跨瀏覽器版本
·開放源代碼,BSD licenced,允許免費使用在個人項目或者商業(yè)項目中
使用 Modello 編寫的類功能可以媲美使用 Atlas 編寫的類,并且使用起來更簡潔。如果你想用 Modello 框架代替 prototype.js 中的簡單類框架,只需要先包含 modello.js,然后去掉 prototype.js 中定義 Class 的幾行代碼即可,一切將正常運行。
ModelloModello 的完整參考說明和下載地址:
http://modello.sourceforge.net/JavaScript Class Framework
Modello is a lightweight framework that enables you to write JavaScript class like other class-based object-oriented programming language. It introduces class, class-based inheritance, multi-inheritance, private members, RTTI and more into JavaScript. Modello can help you write more readable, reusable and maintainable JavaScript code.
ModelloModello下載:
http://sourceforge.net/project/showfiles.php?group_id=164137&package_id=185772Modello.ajax跨域Ajax工具
Ajax是個好東西,但使用起來卻不是那么方便。問題總結(jié)如下:
·在各種瀏覽器上的創(chuàng)建方式和使用方法不一致
·各個瀏覽器對響應(yīng)的緩存策略有所不同
·瀏覽器存在跨域獲取限制
前兩個問題可以通過封裝 XMLHTTPRequest 對象來解決,第三個問題的解決方法有很多中,兼容性和移植性比較好的就是在本域服務(wù)器上放置一個中轉(zhuǎn) proxy 。Modello.ajax 就是提供這套解決方案的工具集。
Modello.ajax下載:
http://sourceforge.net/project/showfiles.php?group_id=164137&package_id=187232ColorCode代碼著色,多語言高亮,使用極為簡單
ColorCode官方網(wǎng)址:
http://www.ajaxwing.com/colorcode/Multi-Language Syntax Highlighter
ColorCode is a multi-language syntax source code highlighter. It is designed to be very easy to use and extend. There is two parts in ColorCode: client-side script and back-end render. You can redefine the color scheme in client-side vias changing the CSS file, and you can also define a new syntax for the language which ColorCode does not support. ColorCode use PEAR's Text_Highlighter as it's back-end render, and supports 14 languages syntax:
c++, css, diff, dtd, html, java, javascript, mysql, perl, php, python, ruby, sql, xml
UsageFirst, include modello.js, ajax.js, colorcode.js and colorcode.css into your html page. Second, define COLORCODE_BACK_END macro. Third, create and ColorCode object and call it's apply() function. And then use textarea tag to wrap the code that need to be rendered with ColorCode.
ColorCode下載:
http://www.ajaxwing.com/download/colorcode.zipNifty Corners CubeJavaScript 圓角(斜角)矩形,同樣使用起來也很快捷。
Nifty Corners Cube官方網(wǎng)址:
http://www.html.it/articoli/niftycube/index.htmlNifty Corners Cube are a solution to get rounded corners without images, and this third version is build by three main components:
·A javascript file, named "niftycornerscube.js"
·A CSS file, named "niftycorners.css"
·The javascript calls specific for the pages
Now we're now ready to look at the first example: it's a div with big rounded corners thanks to Nifty Corners. As I said before, the CSS file it's added automatically by javascript. In fact, the only reference to an external file in the example is the following:
Regarding the third point, as is the javascript calls needed for the page, the code for the example is the following: