goyier 的blog

让学习成为一种生活方式

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  26 随笔 :: 1 文章 :: 0 评论 :: 0 引用

公告

 js的面向对象类型系统使我们能够按照面向对象的规则来定义和使用类:
  <script language="javascript" type="text/javascript">
   //注册命名空间
  Type.registerNamespace("MyCustomNamespace");
  
  //定义构造函数
  MyCustomNamespace.point=function(x,y)
  {
    this._x=x;
    this._y=y;
  }
  
  // 定义属性集合
  MyCustomNamespace.point.prototype=
   {
    get_x:function()
     {
      return this._x;
     }
    get_y:function()
     {
      return this._y;
     }
   toString:function()
     {
       return String.formate("this point:x={0},y={1}",this.get_x(),this.get_y());
     }
   }
   //注册该类
   MyCustomNamespace.point.registerClass("MyCustomNamespace.point");



 </script>
  

posted on 2007-10-23 18:05 goyier 阅读(80) 评论(0) 编辑 收藏