File tree Expand file tree Collapse file tree 2 files changed +46
-7
lines changed Open diff view settings
Expand file tree Collapse file tree 2 files changed +46
-7
lines changed Open diff view settings
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ require ( '../common' ) ;
4+ const assert = require ( 'assert' ) ;
5+ const inherits = require ( 'util' ) . inherits ;
6+
7+ // super constructor
8+ function A ( ) {
9+ this . _a = 'a' ;
10+ }
11+ A . prototype . a = function ( ) { return this . _a ; } ;
12+
13+ // one level of inheritance
14+ function B ( value ) {
15+ A . call ( this ) ;
16+ this . _b = value ;
17+ }
18+ inherits ( B , A ) ;
19+ B . prototype . b = function ( ) { return this . _b ; } ;
20+
21+ assert . strictEqual ( B . super_ , A ) ;
22+
23+ const b = new B ( 'b' ) ;
24+ assert . strictEqual ( b . a ( ) , 'a' ) ;
25+ assert . strictEqual ( b . b ( ) , 'b' ) ;
26+ assert . strictEqual ( b . constructor , B ) ;
27+
28+ // two levels of inheritance
29+ function C ( ) {
30+ B . call ( this , 'b' ) ;
31+ this . _c = 'c' ;
32+ }
33+ inherits ( C , B ) ;
34+ C . prototype . c = function ( ) { return this . _c ; } ;
35+ C . prototype . getValue = function ( ) { return this . a ( ) + this . b ( ) + this . c ( ) ; } ;
36+
37+ assert . strictEqual ( C . super_ , B ) ;
38+
39+ const c = new C ( ) ;
40+ assert . strictEqual ( c . getValue ( ) , 'abc' ) ;
41+ assert . strictEqual ( c . constructor , C ) ;
42+
43+ // should throw with invalid arguments
44+ assert . throws ( function ( ) { inherits ( A , { } ) ; } , TypeError ) ;
45+ assert . throws ( function ( ) { inherits ( A , null ) ; } , TypeError ) ;
46+ assert . throws ( function ( ) { inherits ( null , A ) ; } , TypeError ) ;
Original file line number Diff line number Diff line change @@ -83,10 +83,3 @@ assert.deepEqual(util._extend({a:1}, true), {a:1});
8383assert . deepEqual ( util . _extend ( { a :1 } , false ) , { a :1 } ) ;
8484assert . deepEqual ( util . _extend ( { a :1 } , { b :2 } ) , { a :1 , b :2 } ) ;
8585assert . deepEqual ( util . _extend ( { a :1 , b :2 } , { b :3 } ) , { a :1 , b :3 } ) ;
86-
87- // inherits
88- var ctor = function ( ) { } ;
89- assert . throws ( function ( ) { util . inherits ( ctor , { } ) ; } , TypeError ) ;
90- assert . throws ( function ( ) { util . inherits ( ctor , null ) ; } , TypeError ) ;
91- assert . throws ( function ( ) { util . inherits ( null , ctor ) ; } , TypeError ) ;
92- assert . doesNotThrow ( function ( ) { util . inherits ( ctor , ctor ) ; } , TypeError ) ;
You can’t perform that action at this time.
0 commit comments