[JavaScript]类之二
javascript 类定义4种方法
Java代码
/*
工厂方式--- 创建并返回特定类型的对象的 工厂函数 ( factory function )
*/
function createCar(color,doors,mpg){
var tempCar = new Object;
tempCar.color = color;
tempCar.doors = doors;
tempCar.mpg = mpg;
tempCar.showCar = function(){
alert(this.color + " " + this.doors);
}
return tempCar;
}
/*
构造函数方式--- 构造函数看起来很像工厂函数
*/
function Car(color,doors,mpg){
this.color = color;
this.doors = doors;
this.mpg = mpg;
this.showCar = function(){
alert(this.color);
};
}
/*
原型方式--- 利用了对象的 prototype 属性,可把它看成创建新对象所依赖的原型
*/
function Car(color,doors,mpg){
this.color = color;
this.doors = doors;
this.mpg = mpg;
this.drivers = new Array("nomad","angel");
} &nb
相关文档:
文件内容如下:(两个文件glossy.js和glossy.html)
/********************************** glossy.js ***********************************/
/**
* glossy.js 1.31 (19-Jul-2007)
* (c) by Christian Effenberger
* All Rights Reserved
* Source: glossy.netzgesta.de
* Distrib ......
一、类型转换的方法和应该注意的问题:
1,转换为布尔型:
(1)用两次非运算(!):
!!5 ==> true
(2)用布尔型的构造函数:
new Boolean(5) == > true
值转换为布尔类型为false:
0,+0,-0,NaN,""(空字符串),undefined,null
除上面的值其他值在转换以后为true,需要特别提到的是:
"0",new Object(),funct ......
在web上编写菜单一直是比较头疼的事情,要是有个类直接套用就好了,最近又要做网站了,烦人,要求做的还是多级菜单,唉,废话少说,遇到问题就要解决啊,看代码:
function is(e, handler) {
if (e.type != 'mouseout' && e.type != 'mouseover ......
层的开发在实际应用中比较重要,比如漂浮广告等等,我这里简单探讨一下。
1. 控制层的显示或隐藏
两种办法,其实都是控制样式的。
办法一:控制 display 属性
<script language="javascript">
function show(status)
{
document.getElemen ......