JS的面向对象编程

//JS的面向对象编程

  在这里,原型对象就是类,JS中一切都是类

  1. 使用构造函数定义类,再定义对象实例
  2. This指针每个对象都有一个副本,在函数外可以访问,实现JAVA公有变量和成员变量功能
  3. This包含在一个函数中,指代函数的调用者
  4. Prototype可以使属性方法等重用,实现JAVA中函数和静态变量功能
  5. For(var Key in person1){

             person1[Key];

         }

  1. Prototype不能调用私有变量和方法
  2. 对象冒充形式实现继承(多重继承)

function Person(){
     this.name = "hzm";
     this.age = 24;
     this.speak = function (){
            alert(this.name + this.age);
     };
}

function Chinese(){

         this.person = Person;

         //继承关键

         this.person();

         //覆盖父类的speak函数

         this.speak = function(){

                  alert("Chinese");

         };

}

原文地址:https://www.cnblogs.com/hzmbbbb/p/4279753.html