Skip to content

Commit 1ab3ba5

Browse files
author
a.shatalov
committed
prototypes
1 parent 8a0ce1a commit 1ab3ba5

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

prototype/PrototypeExample.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function Dog(name) {
2+
this.name = name;
3+
}
4+
5+
Dog.prototype.bark = () => console.log('bark');
6+
7+
export function Pug(name) {
8+
Dog.call(this, name);
9+
}
10+
11+
Pug.prototype = Object.create(Dog.prototype);
12+
Pug.prototype.constructor = Pug;
13+
14+
15+
export const atomThePug = new Pug('atom');

prototype/PrototypeExample.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { atomThePug, Dog, Pug } from './PrototypeExample';
2+
describe('atomThePug', () => {
3+
test('properties', () => {
4+
expect(atomThePug.name).toBe('atom');
5+
expect(atomThePug.bark).toEqual(expect.any(Function));
6+
});
7+
test('constructor', () => {
8+
expect(atomThePug.constructor).toEqual(Pug);
9+
expect(atomThePug.constructor).not.toEqual(Dog);
10+
});
11+
test('instanceof', () => {
12+
expect(atomThePug instanceof Pug).toBeTruthy();
13+
expect(atomThePug instanceof Dog).toBeTruthy();
14+
});
15+
test('hasOwnProperty', () => {
16+
expect(atomThePug.hasOwnProperty('bark')).toBeFalsy();
17+
expect(atomThePug.hasOwnProperty('name')).toBeTruthy();
18+
});
19+
});

0 commit comments

Comments
 (0)