Ajax与系列精华Javascript库(Modello)
声明:以下推荐的类均来自互联网的开源项目,版权所有属于原作者。 引用
使用Modello编写JavaScript类
到目前为止,JavaScript 是一种不完全支持面向对象特性的脚本语言。之所以这样说是因为 JavaScript 的确支持对象的概念,在程序中我们看到都是对象,可是 Javascipt 并不支持类的封装和继承。JavaScript 的确支持自定义对象和继承,不过使用的是另外一种方式:prototype(中文译作:原型)。用过 JavaScript 的或者读过《设计模式》的读者都会了解这种技术,描述如下: 每个对象都包含一个 prototype 对象,当向对象查询一个属性或者请求一个方法的时候,运行环境会先在当前对象中查找,如果查找失败则查找其 prototype 对象。注意 prototype 也是一个对象,于是这种查找过程同样适用在对象的 prototype 对象中,直到当前对象的 prototpye 为空。 在 JavaScript 中,对象的 prototype 在运行期是不可见的,只能在定义对象的构造函数时,创建对象之前设定。 使用 Modello 编写的类所具备如下特性: ·私有成员、公共成员和静态成员 ·类的继承,多继承 ·命名空间 ·类型鉴别 Modello 还具有以下特性: ·更少的概念,更方便的使用方法 ·小巧,只有两百行左右的代码 ·设计期和运行期彻底分离,使用继承的时候不需要使用 prototype,也不需要先创建父类的实例 ·兼容 prototype.js 的类,兼容 JavaScript 构造函数 ·跨浏览器,跨浏览器版本 ·开放源代码,BSD licenced,允许免费使用在个人项目或者商业项目中 使用 Modello 编写的类功能可以媲美使用 Atlas 编写的类,并且使用起来更简洁。如果你想用 Modello 框架代替 prototype.js 中的简单类框架,只需要先包含 modello.js,然后去掉 prototype.js 中定义 Class 的几行代码即可,一切将正常运行。 Modello Modello 的完整参考说明和下载地址:http://modello./ 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. Modello Modello下载: http:///project/showfiles.php?group_id=164137&package_id=185772 Modello.ajax 跨域Ajax工具 Ajax是个好东西,但使用起来却不是那么方便。问题总结如下: ·在各种浏览器上的创建方式和使用方法不一致 ·各个浏览器对响应的缓存策略有所不同 ·浏览器存在跨域获取限制 前两个问题可以通过封装 XMLHTTPRequest 对象来解决,第三个问题的解决方法有很多中,兼容性和移植性比较好的就是在本域服务器上放置一个中转 proxy 。Modello.ajax 就是提供这套解决方案的工具集。 Modello.ajax下载: http:///project/showfiles.php?group_id=164137&package_id=187232 ColorCode 代码着色,多语言高亮,使用极为简单 ColorCode官方网址:http://www./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 Usage First, 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./download/colorcode.zip Nifty Corners Cube JavaScript 圆角(斜角)矩形,同样使用起来也很快捷。 Nifty Corners Cube官方网址:http://www./articoli/niftycube/index.html Nifty 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: |
|
来自: 命運之輪 > 《JavaScript》