javascript 学习笔记(5) 继承
1. 某些基类如果不直接使用,而仅仅只是用于给子类提供通用的函数,这种情况下,基类被看作抽象类.
2. 在 javascript 的类中所有的方法和属性都是"公用的".
3. javascript 中的继承并不是明确规定的,而是通过模仿来实现的.有以下方法:
(1). 对象冒充
function A(sColor){
this.color = sColor;
this.showColor = function(){
alert(this.color);
};
}
function B(sColor,sName){
this.newMethod = A;
this.newMethod(sColor);
delete this.newMethod;
this.name = sName; //新的方法和属性要在删除了新方法的定 义后定义
this.showName = function(){
alert(this.name);
};
}
对象冒充方法可以支持多重类继承,也就是一个类可以继承于多个类
如果存在一个类 C 想继承类 A 和 B,只要这样:
function C(){
this.newMethod = A;
this.newMethod();
delete this.newMethod
this.newMethod = B;
this.newMethod();
delete this.newMethod
}
但是要注意如果 A 和 B 中存在同名的属性或者方法,则 B 具有高优先级,因为他是后面的类继承.
(2). call() 方法
function B(sColor,sName){
//this.newMethod = A;
//this.newMethod(sColor);
//delete this.newMethod;
A.call(this,sColor);
this.name = sName;
this.showName = function(){
alert(this.name);
};
}
(3). apply() 方法
function B(sColor,sName){
//this.newMethod = A;
//this.newMethod(sColor);
//delete this.newMethod;
A.apply(this,new Array(sColor));
this.name = sName;
this.showName = function(){
alert(this.name);
};
}
(4). 原型链,原型链不支持多重继承
function A(){
}
A.p
相关文档:
早上在csdn上看有人问页面style sheet怎么修改里面的rule,就写了个类,该类对兼容FF和IE做了处理。
/**//*--------------------------------------------
描述 : 添加新的样式rule
参数 : styleSheets索引
代码 :&nb ......
1. javascript 是区分大小写的,包括变量、函数名等等。
2. javascript 中的变量是弱类型的,定义变量时只用 var 运算符。
var test1 = "hi";
或者
var test1 = "hi",test2 = "hello";
或者(可以是不同的类型)
var test1 = "hi",test2 = 12;
或者(可以不用初始化)
var test1;
3. javascript 每条语句的结尾&ldqu ......
1、使用Page.ClientScript.RegisterClientScriptBlock
RegisterClientScriptBlock方法可以把JavaScript函数放在页面的顶部。也就是说,该脚本用于在浏览器中启动页面。
Code
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object send ......
1.document.formName.item('itemname')的问题
说明:IE下可以使用document.formName.item('itemname')和document.formName.elements('elementsName');
FF下只能使用docuement.formName.elements('elementsName');
解决方法:统一使用docuement.formName.elements('elementsName');
2.集合类对象问题
说明:IE下可以使用[]和 ......
1. 一种面向对象语言需要开发者提供以下四种基本能力。
(1)封装---把相关信息(无论属性还是方法)存储在对象中的能力。
(2)聚集---把一个对象存储在另一个对象内的能力。
(3)继承---由另一个类(或多个类)得来类的属性或方法的能力。
(4)多态---编写能以多种方法运行的函数或方法的能力。
2. 把对象的所 ......