javascript,令人着迷了!
学习了prototype,通过一些联系,尽然对javascrip有了很深的感情,不错.同样是一门优美的语言.一个学习ruby的朋友对我说,动态语言的美感,但是我从对ruby的几天学习,感觉的不是美丽,而是乱.但是,今天,javascript,在prototype的扩展下,显示出了"动态"语言的美,它的语法,它的书写,爽!
特别强调一下,我最爱写的一句话:$A();
呵呵!
一个简单的shortcut,尽然有如此的魅力,真实不可思议.
尝试写自己shortcut中,但这样也许是不能用的,因为标注库的扩展中也会有新的shortcut出现,会不会重复,也许会出现问题,思考中.....
prototype在对javascript OO 方面的扩张,使这个原来用起来,总是感觉怪怪的东东,变的一样具有很强的面向对象的体系结构特性,对于一个学习和使用OO语言的人来说,真实不错.
随便写的,用了OO哦!
var Person = Class.create();
Person.prototype = {
initialize:function(id,name,email,age){
this.Id =id;
this.Name = name;
this.Email = email;
this.Age = age;
},
showSelf:function(element){
var str = "Name:"+this.Name+"\n"+"Email:"+this.Email+"\nAge:"+this.Age;
Element.update(element,str);
}
};
var personList = Class.create();
personList.prototype={
_personList:[],
initialize:function(){
this._personList = new Array();
},
GetLength:function(){return this._personList.length},
add:function(_person){
this._personList[this._personList.length]=_person;
},
remove:function(i){
for(var j=i;j<this._personList.length-1;j++){
this._personList[j]=this.personList[j+1];
}
this._personList.length=this._personList.length-1;
},
del:function(_id){//有些问题
var flag = 0;
if(this._personList!=null){
this._personList.each(function(e){
if(e.Id ==_id){
{
remove(flag);
}
}
flag++;
}); //each
}
},
show:function(element)
{
element = $A(element);
var i=0;
this._personList.each(function(e){e.showSelf(element[i++]);});
}
};
var list = new personList();
function addPerson(id,name,email,age){
p = new Person(id,name,email,age);
list.add(p);
}
function delPerson(id){
if(list.length>0)
list.del(id);
}
function showPerson(element){
list.show(element);
}
function showLength(){
alert(list.GetLength());
}
这个东东的调试真是一件痛苦的事情 :(
但从另外一面来说,这是一个非常好的锻炼的机会,脱离的沉重的IDE,轻装上阵.这不但要求有好的风格,还要有严谨的思考,锻炼啊!
一个搞了半天的问题:
myclass = Class.create();
myclass.prototype={
_personList:[],
initialize:function(){
this._personList = new Array();
},
len : function(){return this._personList.length;}
};
//now , try to invoke the len
first:一直认为这是一个属性啊,所以:
alert(new myclass().len);
出现结果令人吃惊:function(){return this._personList.length;}
一个string
then:这是一个啥?
alert(new myclass().len());
这次对了,但是为啥如此呢?属性也需要这样调用吗?难道说这不是属性?还是别的原因?呵呵,我也不知道,也许就是这样的玩意吧,继续学习中,也许明天就有很好的解释了.....
---------2006.7.9
--------2006.7.8:买了条新裤子,60RMB;一个耳机,global:25RMB!(做个账)
posted on 2006-07-09 22:01 flyingchen 阅读(463) 评论(3) 收藏 举报
浙公网安备 33010602011771号