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

posted on 2013-06-06 16:36  yun007  阅读(355)  评论(0编辑  收藏  举报