-
Notifications
You must be signed in to change notification settings - Fork 4
/
examples-avanced.js
110 lines (99 loc) · 2.45 KB
/
examples-avanced.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// jshint esversion: 6, node: true
"use strict";
if (typeof require !== 'undefined' && typeof equal === 'undefined') {
var equal = require( './esequal' );
}
// nonStrict
if (equal("1", 1, {nonStrict: true})) {
console.log('they are equal');
} else {
console.log('they are not equal');
}
if (equal("1", 1)) {
console.log('they are equal');
} else {
console.log('they are not equal');
}
// nonStrict
var arr1 = ['a', 'b', 'c'];
var arrLike2 = {'0': 'a', '1': 'b', '2': 'c'};
Object.defineProperty(arrLike2, 'length', {value: 3, enumerable: false});
if (equal(arr1, arrLike2, {nonStrict: true})) {
console.log('they are equal');
} else {
console.log('they are not equal');
}
// nonEnumerableProperties
var nonEnumerable = {};
Object.defineProperties( nonEnumerable, {
a: {value: 1, enumerable: false},
b: {value: 2, enumerable: false}}
);
var enumerable = {a: 1, b: 2};
if (equal(enumerable, nonEnumerable, {nonEnumerableProperties: true})) {
console.log('they are equal');
} else {
console.log('they are not equal');
}
// allProperties
var priv = new WeakMap();
class ClassCheck {
constructor() {
priv.set(this, {});
}
get a() {
return priv.get(this).a;
}
set a(value) {
var tmp = priv.get(this);
tmp.a = value;
priv.set(this, tmp);
}
}
var fromClass1 = new ClassCheck();
fromClass1.a = 10;
fromClass1.b = 20;
var fromClass2 = new ClassCheck();
fromClass2.a = 10;
fromClass2.b = 20;
if (equal(fromClass1, fromClass2, {allProperties: true})) {
console.log('they are equal');
} else {
console.log('they are not equal');
}
// checkPropertyDescritors
var notWritable = {};
Object.defineProperties( notWritable, {
a: {value: 1, writable: false, enumerable: true},
b: {value: 2, writable: false, enumerable: true}}
);
var writable = {a: 1, b: 2};
if (equal(notWritable, writable, {checkPropertyDescritors: true})) {
console.log('they are equal');
} else {
console.log('they are not equal');
}
// privateProperties
var priv1 = {
p: true,
_x: 10,
_z: 20
};
var priv2 = {
p: true,
_x: 0,
_z: 0
};
if (equal(priv1, priv2)) {
console.log('they are equal');
} else {
console.log('they are not equal');
}
if (equal(priv1, priv2, {privateProperties: true})) {
console.log('they are equal');
} else {
console.log('they are not equal');
}
if (typeof process !== 'undefined' && typeof process.exit !== 'undefined') {
process.exit( 0 );
}