javascript对象类型

javascript中没有类的概念,由函数模拟类的方式工作。
function Base(){
   //定义属性
   this.id = "123456";
   this.name = "张三";

   //定义方法
   this.show = function show(){
      console.log("姓名:" + this.name);
   }
}

//定义Base类对象bb
var  bb = new  Base();

//为bb对象添加属性或方法(对象名.属性名)
bb.sex = "男";

//删除bb对象中的id属性(对象名.属性名)
delete  bb.id

通过原型模拟继承
创建一个Bird类继承Base类
Bird.prototype = new Base();

//参数可以为普通类型或是类类型 getInfo  str用为普通类型  obj用为Base类的类型
function getInfo(str,obj){
  console.log(str + obj.name);
}



posted @ 2012-03-07 22:20  前端咖  阅读(289)  评论(0编辑  收藏  举报