Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e22016a

Browse files
Add example of isPrototypeOf
1 parent 3ac16e9 commit e22016a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

‎examples/isPrototypeOf/index.html‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>isPrototypeOf Example</title>
6+
<link rel="stylesheet" href="http://code-warrior.github.io/styles/reset.css">
7+
<link rel="stylesheet" href="http://code-warrior.github.io/styles/base.css">
8+
</head>
9+
<body>
10+
<h1><code>isPrototypeOf</code> Example</h1>
11+
<p>Open your console to see this program’s output from the file <a href="isPrototypeOf.js">isPrototypeOf.js</a></p>
12+
<script src="isPrototypeOf.js"></script>
13+
</body>
14+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*jslint es6, single, devel */
2+
/*eslint no-console: ["error", { allow: ["log"] }] */
3+
4+
'use strict';
5+
6+
let dog = {
7+
adoptable: true,
8+
vaccinated: false
9+
};
10+
11+
let puppy = Object.create(dog);
12+
13+
// Is Object.prototype a prototype of dog?
14+
console.log(Object.prototype.isPrototypeOf(dog)); // true
15+
16+
// Is dog a prototype of puppy?
17+
console.log(dog.isPrototypeOf(puppy)); // true
18+
19+
// The prototype chain, or prototypal inheritance, looks like...
20+
console.log(`Object.prototype → dog → puppy`);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /