# 2015年12月18日

## javascript

### 面向对象

```javascript
oDiv.onclick=function(){
    alert(this);
}
```

> 给一对象添加**事件**（click事件），等于给一个对象添加**方法**（function）；

**this**

* 当前发生事件的对象
* 当前的方法属于谁，this就是谁。

**对象的组成**

* 方法——函数：过程、动态的
* 属性——变量：状态、静态的

  **类与对象**

  类：模子 对象：产品

  var arr=new Array(1,2,3,4,5)

Array----- 类 arr ----- 对象

用构造函数加属性 用原型加方法

**继承**

```javascript
A.prototype.show=function ()
{
    alert(this.abc);
};
for(var i in A.prototype)
{
    B.prototype[i]=A.prototype[i];

}
B.prototype.fn=function(){
    alert('abc');
}
var objA=new A();
var objB=new B();

objA.fn();//error.
```

`call()`:可以改变函数`this`的指向。

```javascript
function A(){
    this.abc=12;
}

function B(){
    //这里的this指-->new B(),把A的this指向了B的this，本来给A加的属性，变成给B加的属性。
    A.call(this);
}
```


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
