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函数,哈哈

  • 相关阅读:
    169. Majority Element
    283. Move Zeroes
    1331. Rank Transform of an Array
    566. Reshape the Matrix
    985. Sum of Even Numbers After Queries
    1185. Day of the Week
    867. Transpose Matrix
    1217. Play with Chips
    766. Toeplitz Matrix
    1413. Minimum Value to Get Positive Step by Step Sum
  • 原文地址:https://www.cnblogs.com/yun007/p/3121485.html
Copyright © 2011-2022 走看看