编程的思想就是面向对象,真正的实现,封装,继承,多态!ajax中也可以实现。找个例子来说明!

<script language=javascript type="text/javascript">

            Type.registerNamespace("microsoftajax");//定义命名空间
            microsoftajax.person = function(firstname, lastname) {

                this._firstname = firstname;
                this._lastname = lastname;
            }

            microsoftajax.person.prototype =
              {
                  get_firstname: function() {
                      return this._firstname;
                  },
                  get_lastname: function() {
                      return this._lastname;
                  },
                  toString: function() {
                      return String.format("my first name is {0},lastname is {1}",this.get_firstname(), this.get_lastname());
                  }
              }
              microsoftajax.person.registerClass("microsoftajax.person");

            microsoftajax.employee = function(firstname, lastname, title) {
            microsoftajax.employee.initializeBase(this, [firstname, lastname]);
                this._title = title;
            }
            microsoftajax.employee.prototype =
            {
                get_title: function() {
                    return this._title;
                },
                toString: function() {
                return microsoftajax.employee.callBaseMethod(this, "toString")+" " + "My title is " + this.get_title() + ".";
                }
            }
            microsoftajax.employee.registerClass("microsoftajax.employee", microsoftajax.person);
           
            //
            microsoftajax.student = function(firstname, lastname, title, sex) {
            microsoftajax.student.initializeBase(this, [firstname, lastname,title]);
            this._sex = sex;
            }
            microsoftajax.student.prototype =
            {
                get_sex: function() {
                    return this._sex;
                },
                toString: function() {
                return microsoftajax.student.callBaseMethod(this, "toString") + " " + "My sex is " + this.get_sex() + ".";
                }
            }
            microsoftajax.student.registerClass("microsoftajax.student", microsoftajax.employee);
           
            </script>