1 | /* Javascript Object Inheritance Implementation ______ ________ |
||
2 | * (c) 2016 <[email protected]> __ / / __ \/ _/ _/ |
||
3 | * Licensed under MIT. / // / /_/ // /_/ / |
||
4 | * ------------------------------------------------------ \___/\____/___/__*/ |
||
5 | var JOII = require('../../dist/joii').JOII; |
||
6 | |||
7 | /** |
||
8 | * Tests class property meta data and validation. |
||
9 | */ |
||
10 | test('ClassBuilder:ConstantTest', function(assert) { |
||
11 | |||
12 | var c1 = JOII.ClassBuilder({ |
||
0 ignored issues
–
show
|
|||
13 | 'const FIRST' : 1, |
||
14 | 'const SECOND' : 2, |
||
15 | 'const THIRD' : 3 |
||
16 | }); |
||
17 | |||
18 | var c2 = JOII.ClassBuilder({'extends': c1}, { |
||
19 | 'const FOURTH' : 4, |
||
20 | 'const FIFTH' : 5, |
||
21 | 'const SIXTH' : 6, |
||
22 | |||
23 | __construct: function() { |
||
24 | this.FOURTH = 3; |
||
25 | assert.strictEqual(this.FOURTH, 4, 'this.FOURTH is still 4 after modification.'); |
||
26 | } |
||
27 | }); |
||
28 | |||
29 | var c3 = JOII.ClassBuilder({'extends': c1}, { |
||
30 | 'const SEVENTH' : 7, |
||
31 | 'const EIGHTH' : 8, |
||
32 | 'const NINTH' : 9 |
||
33 | }); |
||
34 | |||
35 | assert.strictEqual(c1.FIRST, 1, 'FIRST is defined in c1'); |
||
36 | assert.strictEqual(c1.SECOND, 2, 'SECOND is defined in c1'); |
||
37 | assert.strictEqual(c1.THIRD, 3, 'THIRD is defined in c1'); |
||
38 | |||
39 | assert.strictEqual(c2.FIRST, 1, 'FIRST is defined in c2'); |
||
40 | assert.strictEqual(c2.SECOND, 2, 'SECOND is defined in c2'); |
||
41 | assert.strictEqual(c2.THIRD, 3, 'THIRD is defined in c2'); |
||
42 | assert.strictEqual(c2.FOURTH, 4, 'FOURTH is defined in c2'); |
||
43 | assert.strictEqual(c2.FIFTH, 5, 'FIFTH is defined in c2'); |
||
44 | assert.strictEqual(c2.SIXTH, 6, 'SIXTH is defined in c2'); |
||
45 | assert.strictEqual(typeof(c2.SEVENTH), 'undefined', 'SEVENTH is not defined in c2'); |
||
46 | assert.strictEqual(typeof(c2.EIGHTH), 'undefined', 'EIGHTH is not defined in c2'); |
||
47 | assert.strictEqual(typeof(c2.NINTH), 'undefined', 'NINTH is not defined in c2'); |
||
48 | |||
49 | assert.strictEqual(c3.FIRST, 1, 'FIRST is defined in c3'); |
||
50 | assert.strictEqual(c3.SECOND, 2, 'SECOND is defined in c3'); |
||
51 | assert.strictEqual(c3.THIRD, 3, 'THIRD is defined in c3'); |
||
52 | assert.strictEqual(c3.SEVENTH, 7, 'SEVENTH is defined in c3'); |
||
53 | assert.strictEqual(c3.EIGHTH, 8, 'EIGHTH is defined in c3'); |
||
54 | assert.strictEqual(c3.NINTH, 9, 'NINTH is defined in c3'); |
||
55 | assert.strictEqual(typeof(c3.FOURTH), 'undefined', 'FOURTH is not defined in c3'); |
||
56 | assert.strictEqual(typeof(c3.FIFTH), 'undefined', 'FIFTH is not defined in c3'); |
||
57 | assert.strictEqual(typeof(c3.SIXTH), 'undefined', 'SIXTH is not defined in c3'); |
||
58 | |||
59 | // Test writability |
||
60 | c3.FIRST = 2; |
||
61 | assert.strictEqual(c3.FIRST, 1, 'FIRST is still 1 in c3'); |
||
62 | }); |
||
63 |
Strict mode is a way to opt-in to a restricted variant of JavaScript. It eliminates some common pitfalls by being less lenient and raising more errors.
Besides, it is also used to fix certain mistakes which made it difficult for JavaScript runtimes to perform certain optimizations.
We generally recommend to only enable strict mode on the function scope and not in the global scope as that might break third-party scripts on your website.