Skip to content

Commit 441b80c

Browse files
committed
proto inheritance
1 parent cbf5403 commit 441b80c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# JavaScript Prototypal Inheritance
2+
3+
> [http://youtu.be/qMO-LTOrJaE](http://youtu.be/qMO-LTOrJaE)
4+
5+
Install [io.js](https://iojs.org/en/index.html).
6+
7+
Within this folder run the terminal command `npm install` to install the
8+
`devDependencies`.
9+
10+
Then run `npm start` to start up a development server on `http://localhost:9966`
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function Bear(type) {
2+
this.type = type
3+
}
4+
Bear.prototype.growl = function() {
5+
console.log('The ' + this.type + ' bear says grrr')
6+
}
7+
8+
function Grizzly() {
9+
Bear.call(this, 'grizzly')
10+
}
11+
Grizzly.prototype = Object.create(Bear.prototype)
12+
// Grizzly.prototype.growl = function() {
13+
// console.log('on the Grizzly.prototype')
14+
// }
15+
16+
//var grizzly = new Bear('grizzly')
17+
18+
var grizzly = new Grizzly()
19+
var polar = new Bear('polar')
20+
21+
22+
//grizzly.growl = function() { console.log('override') }
23+
console.log(grizzly.growl())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "javascript-prototypal-inheritance",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "budo index.js --live"
8+
},
9+
"author": "Kyle Robinson Young <[email protected]> (http://dontkry.com)",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"budo": "^3.1.1",
13+
"watchify": "^3.1.2"
14+
}
15+
}

0 commit comments

Comments
 (0)