1 1, function func() {
2 return // return undefined;
3 {
4 name: ‘redky’;
5 };
6 }
7
8 function func() {
9 return {
10 name: ‘redky’;
11 };
12 }
13 2, @namespace 指对象命名空间. @class 命名空间下二级命名空间 @module myapp
14 @method 方法名 @param 参数 @return
15 3, var person = {};
16 person.say = function () {
17 console.log(‘say method’);
18 }
19 person.name = ‘redky;
20
21 var person = {
22 name: ‘redky’,
23 say: function () {
24 console.log(‘say method’);
25 }
26 };
27 4,
28 var Person = function () {
29 this.name = ‘redky’;
30 var that = {};
31 that.name = ‘xiaoyi’;
32 return that;
33 };
34 var p = new Person();
35 console.log(p.name); // xiaoyi
36 5, In jQuery, there’s the parseJSON() method.
37 var person = {“name”: ‘redky”’};
38 var data = jQuery.parseJSON(person);// in morden browser, JSON.parse(person);
39 // JSON.stringify(data); –>person {string}
40 6, var reg = /\\/gm;
41 var reg = new RegExp(‘\\\\’, ‘gim’);
42 example:
43 // 转义正则中特殊字符
44 function convertReg(s) {
45 return s.replace(/\$/g, ‘\\$’)
46 .replace(/\\/g, ‘\\\\’)
47 .replace(/\^/g, ‘\\^’)
48 .replace(/\*/g, ‘\\*’)
49 .replace(/\?/g, ‘\\?’)
50 .replace(/\+/g, ‘\\+’)
51 .replace(/\./g, ‘\\.’)
52 .replace(/\|/g, ‘\\|’)
53 .replace(/\[/g, '\\[')
54 .replace(/\]/g, ‘\\]’)
55 .replace(/\(/g, ‘\\(‘)
56 .replace(/\)/g, ‘\\)’)
57 .replace(/\{/g, ‘\\{‘)
58 .replace(/\}/g, ‘\\}’);
59 }
60 7, try {
61 throw {
62 name: ‘error type’;
63 message: ‘oops’;
64 }
65 }
66 catch (e) {
67 console.log(e)
68 }