9、YUI的写类方式
这里引入的是YUI 2.7.0版,只需引入yahoo.js。YUI引入了命名空间,类似于java的包。以下yahoo的工具函数包
YAHOO.namespace
YAHOO.lang
YAHOO.lang.hasOwnProperty
YAHOO.lang.extend
YAHOO.lang.augment
YAHOO.log
YAHOO_config and YAHOO.env
YUI Module Names
写类方式:
//定义包名
YAHOO.namespace("test");
//定义类
YAHOO.test.Person = function(name) {
this.name = name;
}
YAHOO.test.Person.prototype.setName = function(name){ this.name = name;}
YAHOO.test.Person.prototype.getName = function(){ return this.name;}
//创建一个对象
var p = new YAHOO.test.Person("jack");
console.log(p.getName());//jack
p.setName('tom');
console.log(p.getName());//tom
//测试instanceof及p.constructor是否正确指向了YAHOO.test.Person
console.log(p instanceof YAHOO.test.Person);
console.log(p.constructor == YAHOO.test.Person);
可以看出除了多了包名,与第三种写类方式
并无区别。 ......
10、mootools.js的写类方式
mootools.js的最新版本是1.2.3,这里使用的是1.2.0。mootool被设计成非常紧凑的,模块化的,面向对象的的js库。mootool中写类用Class类。Class类由Native类new出来的:
/*
*Script: Class.js
*/
var Class = new Native({
name: 'Class',
initialize: function(properties){
properties = properties || {};
var klass = function(empty){
for (var key in this) this[key] = $unlink(this[key]);
for (var mutator in Class.Mutators){
if (!this[mutator]) continue;
Class.Mutators[mutator](this, this[mutator]);
delete this[mutator];
}
this.constructor = klass;
if (empty === $empty) return this;
var self = (this.initialize) ? this.initialize.apply(this, arguments) : this;
if (this.options && this.options.initialize) this.options.initialize.call(this);
return self;
};
$extend(klass, this);
klass.constructor = Class;
klass.prototype = properties;
return klass;
}
});
Native方法是mootools中一个非常重要的 ......
这两天上午一直在学习JavaScript,由于总是在看,效果不是很大,也好久没有发表文章了,所以为了更好的学习,把学到的东西记录下来。我学习JavaScript的书是《精通JavaScript+jQuery》,如果大家有更好的书请推荐。
一. 事件的概念
C#中事件的定义:事件类似于异常,它们都由对象引发,可以提供代码来处理事件。
我的理解是:当发生某件事时,用相应的方法去处理。
二. 事件流
浏览器中事件分为两种:冒泡型事件和捕获型事件。
冒泡型事件:从DOM层次的最低端一级级往上升。
捕获型事件:与冒泡型事件正好相反,从最不精确的到最精确的。
三. 事件监听
有三种方式可以设置监听。
1.HTML标签中直接分配事件处理函数。
<p onclick="alert('我被点击了');">Click Me</p>
2.结构行为分离:
<script language=" ......
Do you want an ultra fast web site? Get JSL and optimize your JavaScript loading now!
Imagine there's a 4-lane highway between your web browser and the internet itself. This highway is optimize to let pictures, text, and css fly by. But, when it comes to external scripts, the highway creates a toll booth that slows traffic. The worst part is that pictures text, and css caught behind these scripts have to wait until they pass through. JSL is the latest in toll both avoidance. It creates an express lane that lets all pictures, text, css, and external scripts pass by without worrying about toll booths. That means you save time and money on traffic costs :)
Now for the the techie information...
Features
On-Demand JavaScript Loading new
Browser Cacheable new
Dynamic Asynchronous JavaScript Loading
Lazy Loading
Ordered Loading
Duplicate Source Prevention updated
Ultra Fast and Lightweight
Use DOM or Script Tag writing
Cross-browser
Cross Domain read ......
1 框架编程概述
一个Html 页面可以有一个或多个子框架,这些子框架以<iframe>来标记,用来显示一
个独立的Html 页面。这里所讲的框架编程包括框架的自我控制以及框架之间的互相访问,
例如从一个框架中引用另一个框架中的JavaScript变量、调用其他框架内的函数、控制另一
个框架中表单的行为等。
2 框架间的互相引用
一个页面中的所有框架以集合的形式作为window 对象的属性提供,例如:
window.frames 就表示该页面内所有框架的集合,这和表单对象、链接对象、图片对象等是
类似的,不同的是,这些集合是document 的属性。因此,要引用一个子框架,可以使用如
下语法:
Javascript 代码
window.frames[“frameName”];
window.frames.frameName
window.frames[index]
其中,window字样也可以用self代替或省略,假设frameName 为页面中第一个框架,
则以下的写法是等价的:
JavaScript 代码
self.frames[“frameName”]
self.frames[0]
frames[0] ......
如果想从网页提交参数到服务器,第一个想到的就是Http的Form标签。它将用户在客户端网页填写的数据通过HTTP Post,提交到服务端。这些提交的数据被放在HTTP消息的body里面,这样,用户提交的数据理论上是没有长度限制的。如果服务端用的是J2EE,HttpServletRequest可以非常轻松得取到所有参数,非常完美。
但是,有一些特殊的应用,如果服务端不是J2EE,没有HttpServletRequest,而是Java Socket实现,接受到的HTTP消息是最原始的字节流。这些字节流被一个简单的HTTP Message解析器解析。问题是,为了处理简单,这个解析器只解析了HTTP消息的头部,没有解析HTTP消息的body部分。这时,客户端需要提交一些长度有限的数据给服务端,如果还是用Form提交数据,显然通不过。很自然,数据只能存在HTTP消息的头部。这是Form做不到的,应该求助于其他的脚本工具,这里介绍JavaScript的XMLHttpRequest。
XMLHttpRequest可以在HTTP消息的头部增加扩展的meta header,也可以像Form一样,把数据提交到HTTP消息的body部分。下面这段代码是一个自动提交的例子。"http://localhost:8080/Tes ......