js-function

  1. function是一个函数

    执行函数的过程

    1. 第一种调用

      1. 声明一个函数

        1
        2
        3
        function Person(){
        alert("person");
        }
      2. 调用函数

        1
        Person();调用一个函数
    2. 第二种调用

      1. 可以给页面上一个元素添加点击事件
      2. 当该元素的事件触发后,执行该函数
  2. function是一个对象

    1. 在js中对象中的属性是动态添加的

      1. 第一种

        1
        Person.a = 5;//给person对象动态添加了一个属性,属性名称为"a",值为"5"
      2. 第二种

        1
        2
        3
        4
        5
        //Student对象
        function Student(){

        }
        Person.b = Student;//动态的给Person对象创建了一个属性,属性名称为"b",值为"Student"
      3. 第三种

        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        //声明了一个json格式的对象,名字为json
        var json = {
        a:function(){
        alert("aaa");
        }
        };
        Person.c = json;//动态的给Person对象创建了一个属性c,值为json
        /*
        * Person是一个对象,c是Person的一个属性,但是c也是一个对象,a是c对象里的一个属性,a也是一个对象
        */
        Person.c.a();
      4. 第四种

        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        //Ext.button.Button();
        function Ext(){//是一个对象

        }
        function abutton(){//是一个对象

        }
        function cutton(){//是一个对象
        alert("cutton");
        }
        Ext.button = abutton;
        Ext.button.Button = cutton;
        Ext.button.Button();
      5. 第五种

        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
        //A.B.C.D.E.F.G()
        function A(){

        }
        function b(){

        }
        function c(){

        }
        function d(){

        }
        function e(){

        }
        function f(){

        }
        function g(){
        alert("gg");
        }
        A.B=b;
        A.B.C=c;
        A.B.C.D=d;
        A.B.C.D.E=e;
        A.B.C.D.E.F=f;
        A.B.C.D.E.F.G=g;

        说明:

        ​ A.B.C.D.E.F称为命名空间,一般情况下命名空间是按模块划分的

        例如:cn.itcast.oa.system.privilege.Menuitemtree

        ​ 是oa项目下的system模块下权限(privilege)下的菜单树

      6. 第六种

        1
        2
        3
        4
        function Person(){

        }
        Person.a = 5;

        说明:a不是一个对象,只是一个整形的值,所以a不存在属性

js-prototype

  1. 在js中一切皆对象

    对象是由谁产生的呢?是由改对象的constructor所指向的构造器函数产生的

    在js中每一个对象都有一个默认的属性constructor

  2. prototype

    1. 一个函数对象有一个默认的属性为prototype

      js的对象可以分为2种

      1
      2
      3
      4
      5
      function Person(){//这种情况是有prototype

      }
      var json = {} //这种情况没有prototype
      {} = new Object({});
    2. prototype的初始化值是一个空的json格式的对象

    3. 可以利用prototype.属性的方式动态的给prototype添加key,value的值

    4. 可以利用prototype[‘属性’]的方式动态的给prototype添加key,value的值