javascript深刻浅出 OPP

概念web

    定义:模块化

        Object-oriented programming    面向对象程序设计函数

        对象是类的实例this

        它将对象做为程序的基本单元spa

        将程序和数据封装在其中prototype

        以提升软件的重用性,灵活性和扩展性设计

    特性:code

    ​    ​继承
orm

    ​    ​封装对象

    ​    ​多态


继承

    基于原型的继承:

    ​    ​prototype属性与原型

    ​    ​原型中的prototype指向父类

    改变prototype:

    ​    ​修改某项属性,前面受影响

    ​    ​重写prototype,前面不受影响

    实现继承的方式:

1
Student.prototype =  new  Person();
1
2
Student.prototype =
Object .create(Person.prototype);
1
2
3
4
5
6
7
if  (! Object .create) {
     Object .create =  function  (prototype) {
         function  F() {}
         F.prototype = prototype;
         return  new  F();
     };
}


模拟

    模拟重载:

    ​    ​根据参数类型和参数个数分别执行

    ​    ​经过arguments和typeof类型判断实现

    链式调用:

        核心:return this

    模块化:

    ​    ​函数当即执行返回给变量

1
2
3
4
5
6
7
8
9
var  module =  function  () {
     var  name =  'guo' ;
     function  fun() {
     }
     return  {
         name: name,
         fun: fun
     };
}();


 

相关文章
相关标签/搜索