May
16
1.第一种方式,冒充对象的方式.(利用js里的每一个方法名都是一个Function对象)
//第一种方式,冒充对象的方式.(利用js里的每一个方法名都是一个Function对象)
function Parent(username){
this.username = username;
this.say = function(){
alert(this.username);
}
}
function Child(username,password){
this.temp = Parent;//temp指向Parent所指向的地方 。 利用js里的每一个方法名都是一个Function对象,指向一个方法。
this.temp(username);//初始化方法里的内容
delete this.temp;//temp没有用了。可以直接删除掉.this不可以丢了
//Parent(username);//这样写表面看起来是正确的,其实是错误的。因为只有new出来的对象才有this,所以调用Parent里的this就没有值了
this.password = password;
this.hello = function(){
alert(this.password);
}
}
var parent = new Parent("zhangsan");
parent.say();//zhangsan
var child = new Child("lisi","123456");
child.say();//lisi
child.hello();//123456
function Parent(username){
this.username = username;
this.say = function(){
alert(this.username);
}
}
function Child(username,password){
this.temp = Parent;//temp指向Parent所指向的地方 。 利用js里的每一个方法名都是一个Function对象,指向一个方法。
this.temp(username);//初始化方法里的内容
delete this.temp;//temp没有用了。可以直接删除掉.this不可以丢了
//Parent(username);//这样写表面看起来是正确的,其实是错误的。因为只有new出来的对象才有this,所以调用Parent里的this就没有值了
this.password = password;
this.hello = function(){
alert(this.password);
}
}
var parent = new Parent("zhangsan");
parent.say();//zhangsan
var child = new Child("lisi","123456");
child.say();//lisi
child.hello();//123456
May
15
javascript里构建类主要有4种方式
1.构造方式定义类
2.原型方式定义类
3.构造和原型结合方式创建类
4.动态的原型方式
各有优缺点,具体如下
1.构造方式定义类,优点:多个实例对象不共享类的属性值,缺点:每个实例对象都会产生出一个函数say
1.构造方式定义类
2.原型方式定义类
3.构造和原型结合方式创建类
4.动态的原型方式
各有优缺点,具体如下
1.构造方式定义类,优点:多个实例对象不共享类的属性值,缺点:每个实例对象都会产生出一个函数say
May
13
1.
User = function (){
}
User.prototype.name = "zhangsan";
//User.name = "zhangsan";//错误定义
var u = new User();
u.password = "123456";
//u.prototype.password = "987654";//错误定义
alert(u.name);
alert(u.password);
}
User.prototype.name = "zhangsan";
//User.name = "zhangsan";//错误定义
var u = new User();
u.password = "123456";
//u.prototype.password = "987654";//错误定义
alert(u.name);
alert(u.password);
May
12
1.js不支持重载,因为js里的函数都是一个对象,js里有个隐含对象Function,所有的js函数都是一个Function类型的对象。比如:
等价于
function add(number)
{
alert("hello");
}
function add(number)
{
alert("hello");
}
{
alert("hello");
}
function add(number)
{
alert("hello");
}
等价于
var add = new Function("number","alert('hello');");
var add = new Function("number","alert('hello');");
var add = new Function("number","alert('hello');");
May
9
1. 集合类对象问题
现有代码中许多集合类对象取用时使用 (),IE 能接受,Firefox 不能。
解决方法:改用 [] 作为下标运算。如:document.forms("formName") 改为
2. DIV对象
在 IE 中,DIV对象可以使用ID作为对象变量名直接使用。在 Firefox 中不能。
DivId.style.display = "none";
解决方法:document.getElementById("DivId").style.display = "none";
ps:得对象的方法不管是不是DIV对象,都应该使用getElementById方法。
现有代码中许多集合类对象取用时使用 (),IE 能接受,Firefox 不能。
解决方法:改用 [] 作为下标运算。如:document.forms("formName") 改为
document.forms["formName"];
//又如:
document.getElementsByName("inputName")(1);
//改为
document.getElementsByName("inputName")[1];
//又如:
document.getElementsByName("inputName")(1);
//改为
document.getElementsByName("inputName")[1];
2. DIV对象
在 IE 中,DIV对象可以使用ID作为对象变量名直接使用。在 Firefox 中不能。
DivId.style.display = "none";
解决方法:document.getElementById("DivId").style.display = "none";
ps:得对象的方法不管是不是DIV对象,都应该使用getElementById方法。
Dec
11
摘要:
本文演示了使用 JS函数 动态插入 UBB 标签到 表单文本域的操作.
本文并没有演示进行 UBB 标签转换为 HTML 标签的操作
说明:
HTML编辑器需要ActiveX支持, 并不是所有浏览器都支持, 比如Opera.
因此对于HTML编辑器和UBB编辑器, 两者我选择 UBB, 因为鄙人习惯使用 OPERA 浏览器, 写的东西当然也得适用于Opera.
本文演示了使用 JS函数 动态插入 UBB 标签到 表单文本域的操作.
本文并没有演示进行 UBB 标签转换为 HTML 标签的操作
说明:
HTML编辑器需要ActiveX支持, 并不是所有浏览器都支持, 比如Opera.
因此对于HTML编辑器和UBB编辑器, 两者我选择 UBB, 因为鄙人习惯使用 OPERA 浏览器, 写的东西当然也得适用于Opera.