zoukankan      html  css  js  c++  java
  • js命名空间与API的编写

     1 <script>
     2     //**************************【函数API示例】********************//
     3     //1、使用一个命名空间定义一个空对象
     4     var MYAPP = {};
     5     //2、在该空间中,定义一个math_stuff对象
     6     /**
     7     * @namespace MYAPP
     8     * @class math_Stuff
     9     * @description 定义一个数学类
    10     */
    11     MYAPP.math_Stuff = {
    12         /**
    13         * sum two numbers
    14         * @method sum
    15         * @param {Number} 第一个数
    16         * @param {Number} 第二个数
    17         * @return {Number} 两个输入的总和
    18         */
    19         sum:function (a,b) {
    20             return a + b;
    21         },
    22         /**
    23         * multiple two numbers
    24         * @method sum
    25         * @param {Number} 第一个数
    26         * @param {Number} 第二个数
    27         * @return {Number} 两个输入的乘积
    28         */
    29         multi:function (a,b) {
    30             return a * b;
    31         }
    32 
    33     };//MYAPP.math_Stuff
    34     //******第二个类,利用函数原型方法
    35     /**
    36     * Constructors Person obhjects
    37     * @class Person
    38     * @constructor
    39     * @namespace MYAPP
    40     * @param {string} first 是名字
    41     * @param {string} last 是姓氏
    42     */
    43     MYAPP.Person = function (first,last){
    44         /**
    45         * First Name
    46         * @property first_name
    47         * @type string
    48         */
    49         this.first_name = first;
    50         /**
    51         * Last name
    52         * @property last_name
    53         * @type string
    54         */
    55         this.last_name = last_name;
    56     };//person
    57     /**
    58     * return the name of person
    59     * @method getName
    60     * @return {string} 人的姓名
    61     */
    62     MYAPP.Person.prototype.getName = function(){
    63         return this.first_name + ' ' + this.last_name;
    64     }
    65 </script>

    尝试开辟一个自己的空间并且在该空间里编写自己的API函数,哈哈

  • 相关阅读:
    poj 2418 Hardwood Species
    hdu 3791 二叉搜索树
    九度oj 1544 数字序列区间最小值
    九度oj 1525 子串逆序打印
    九度oj 1530 最长不重复子串
    九度oj 1523 从上往下打印二叉树
    P1190 接水问题
    P1179 数字统计
    P1083 借教室
    P1079 Vigenère 密码
  • 原文地址:https://www.cnblogs.com/yun007/p/3121485.html
Copyright © 2011-2022 走看看