漫漫技术人生路

C#

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

继续学习javascript  delegate object
<body onload="gg();">

// JScript 文件

object =new Object();

object.a="33";
object["c"]="44";
object.GetTotal=function(){alert(this.a+this.b);};


function gg()//在这里实现调用
{
  object.GetTotal();
 
  myAnimal.study();
 
  alert(myAnimal.sex);
 
  var fristStudent = new student("alex");//类的实例化
 
  fristStudent.play();
 
  var secondStudent = new  studentprototype("mo");
   alert(secondStudent.age);
  
   (myAnimal.sex).adverse();
 
}
//---------------------------------
var myAnimal={
    name:"alex",
    sex:"male",
    age:"20",
    study:function(){alert("good");},
    play:function() {alert("basketball");}
}
//-----------------------------------------
function student(name)
{
    this.name=name;
    this.sex ="male";
    this.age="20";
    this.study=function(){alert("good");},
    this.play =function() {alert("basketball");}

}
//------------------------------------------
function studentprototype(name)
{
  this.name = name;
}

studentprototype.prototype.sex="male";
studentprototype.prototype.age="20";
studentprototype.prototype.study=function(){alert("good");};
studentprototype.prototype.play=function(){alert("basketball");};
//------------------------------------------------

String.prototype.reverse = function(){
   var out = '';
   for(var i=this.length-1; i>=0; i--)
   {     
     out+=this.substr(i, 1);   
   }
      return out;
   }
   alert('asdf'.reverse());
  
  
  
   String.prototype.adverse=function(){
  re(this);
};


function re(obj)
{
  var out="";
 for(var i=obj.length-1;i>=0;i--)
 {
    out += obj.substr(i,1);
 }
 
 alert(out);
}
//--------------------------------------------------------------------------------

posted on 2006-12-07 16:47  javaca88  阅读(511)  评论(0)    收藏  举报