Skip to content

Commit

Permalink
add description
Browse files Browse the repository at this point in the history
  • Loading branch information
SDLyu committed Nov 12, 2013
1 parent ba8fb8f commit c4595e7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Core/Prototype.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ function parent(){
//...
}

parent.prototype.parentcall = function(){
cosole.log("parent!")
}

function child(){
//...
}
Expand All @@ -72,3 +76,10 @@ child.prototype.constructor = child;
```

`child` 類別的 `prototype` 屬性指向父類別的實體,讓 `child` 繼承 `parent`,由於子類別的 `prototype` 屬性已經完全指向父類別實體,所以要手動恢復。

```javascript
var peter = new child();
peter.parentcall(); // output parent!
```

創建出 `peter` 後呼叫 `parentcall()` 方法。由於 `child` 裡沒有 `parentcall` 方法,所以會沿著原型鍊查找到 `parent``parentcall()`。藉由原型鍊查找的方式來達到繼承。

0 comments on commit c4595e7

Please sign in to comment.