> For the complete documentation index, see [llms.txt](https://note.niefee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://note.niefee.com/summary-1/12/2015-nian-12-yue-9-ri.md).

# 2015年12月9日

## cookie

cookie特点：

* 同一个网站的所有页面共享一套cookie
* 数量、大小有限
* 过期时间

**Date()对像**

```

Date()          返回当日的日期和时间。
getDate()       从 Date 对象返回一个月中的某一天 (1 ~ 31)。
getDay()        从 Date 对象返回一周中的某一天 (0 ~ 6)。
getMonth()      从 Date 对象返回月份 (0 ~ 11)。
getFullYear()   从 Date 对象以四位数字返回年份。

setDate()       设置 Date 对象中月的某一天 (1 ~ 31)。
setMonth()      设置 Date 对象中月份 (0 ~ 11)。
setFullYear()   设置 Date 对象中的年份（四位数字）。
```

javascript使用cookie

* document.cookie

设置cookie函数

```javascript
function setCookie(name,value,iDay){
    var oDate=new Date();
    oDate.setDate(oDate.getDate()+iDay);
    document.cookie=name+'='+value+';expires='+oDate;
}

function getCookie(name){
    var arr=document.cookie.split("; ");
    for(var i=0;i<arr.length;i++){
        var arr2=arr[i].split("=");
        if(arr2[0]==name){
            return arr2[1];
        }
        return '';
    }
}

function removeCookie(name){
    setCookie(name,1,-1);
}
```

## 正则表达式

> 强大的字符串匹配工具

`search()`:返回寻找的字符串的位置，没有就会返回-1； `charAt()`:返回某个指定位置下的字符； `substring()`:获取子字符串； //不包括结束位置 `split()`:分割字符串，获得数组。

```javascript
var str='abcdef';

alert(str.search('u'));     //位置, -1
alert(str.charAt(0));       //'a'
alert(str.substring(2, 5));   //cde,不包括结束位置
```

**null与undefined**

```javascript
5+null
//5
6+undefined
//NaN
```

> null是一个表示"无"的对象，转为数值时为0；undefined是一个表示"无"的原始值，转为数值时为NaN。

目前的用法

**null表示"没有对象"，即该处不应该有值。典型用法是：**

* 作为函数的参数，表示该函数的参数不是对象。
* 作为对象原型链的终点。

  Object.getPrototypeOf(Object.prototype)// null

**undefined表示"缺少值"，就是此处应该有一个值，但是还没有定义**。典型用法是：

1. 变量被声明了，但没有赋值时，就等于undefined。
2. 调用函数时，应该提供的参数没有提供，该参数等于undefined。
3. 对象没有赋值的属性，该属性的值为undefined。
4. 函数没有返回值时，默认返回undefined。

```javascript
var i;
i // undefined

function f(x){console.log(x)}
f() // undefined

var  o = new Object();
o.p // undefined

var x = f();
x // undefined
```

**正则表达式写法**

```javascript
var re=new RegExp('b', 'i');//js风格，'b'就代表字母'b','i'代表忽略大小写。
//或者
var re=/a/i;//perl风格

alert(str.search(re));//1
```

**转义字符**

`i`:代表忽略大小写;

`g`:全局匹配；

`+`:若干个；

`|`:或

`[]`:里面的其中一个跟外面的组合匹配；例如'var re=/\[apx]pc/g;'。

`[^a-z]`:排除英文字母，\[0-9]等于`\d`。

`^`:在`[]`里表示排除，在其他位置是行首的意思。

`$`:行尾；

> `re=/^\w+@[a-z0-9]+\.[a-z]+$/i`,邮箱校验，有`^`与`$`可以限制整个字符串都要符合正则表达式，而不是部分。

`.`(点):任意字符；

`\d`:匹配数字；\[0-9]

`\w`:英文、数字、下划线;\[a-z0-9]

`\s`:空白字符;

`\D`:;

`\W`:;

**量词**

`{n}`:正好出现n次；

`\d{8}`:至少八次; `[1-9]\d{7}`:匹配电话号码要求；

`{n,m}`:最少n次，最多m次；

`{n,}`:最少n次，最多不限；

`+`:{1，};

`?`:{0,1}，可以有，或者没有。

`(0\d{2,3}-)?[1-9]\d{7}(-\d{1,5})?`,固定电话规则；

`*`:{0,}任意次，不建议使用。

**常用函数**

`match()`:把所有匹配的都提取出去。

`test()`:检验是否符合正则要求，返回boolean；只要字符串一部分要求，就会返回true，

```javascript
var str='abcdef 8223 234 24 346 35dfsh8 h9 h98 h98898h 89h';
var re=/\d+/g;

alert(str.match(re));//8223 234 24 346 35 8 9 98 98898 89
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://note.niefee.com/summary-1/12/2015-nian-12-yue-9-ri.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
