File tree Expand file tree Collapse file tree 1 file changed +39
-8
lines changed
test_code/javascript_node Expand file tree Collapse file tree 1 file changed +39
-8
lines changed Original file line number Diff line number Diff line change 1
- function add ( a , b ) {
2
- return a + b ;
1
+ class Parent {
2
+ constructor ( ) {
3
+ this . name = "Parent" ;
4
+ }
5
+
6
+ callChild ( ) {
7
+ const child = new Child ( ) ;
8
+ child . callGrandchild ( ) ;
9
+ }
10
+ }
11
+
12
+ class Child extends Parent {
13
+ constructor ( ) {
14
+ super ( ) ;
15
+ this . name = "Child" ;
16
+ }
17
+
18
+ callGrandchild ( ) {
19
+ const grandchild = new Grandchild ( ) ;
20
+ grandchild . printStackTrace ( ) ;
21
+ }
3
22
}
4
23
5
- const greeting = "Hello, world!" ;
6
- console . log ( greeting ) ;
24
+ class Grandchild extends Child {
25
+ constructor ( ) {
26
+ super ( ) ;
27
+ this . name = "Grandchild" ;
28
+ }
7
29
8
- const number = 42 ;
9
- console . log ( "The number is:" , number ) ;
30
+ printStackTrace ( ) {
31
+ console . trace ( `Stack trace for ${ this . name } ` ) ;
32
+ }
33
+ }
34
+
35
+ const obj = new Parent ( ) ;
36
+ obj . callChild ( ) ;
37
+
38
+ function showAllStackTraces ( ) {
39
+ const grandchild = new Grandchild ( ) ;
40
+ grandchild . printStackTrace ( ) ;
41
+ }
10
42
11
- const result = add ( 5 , 3 ) ;
12
- console . log ( "The sum is:" , result ) ;
43
+ showAllStackTraces ( ) ;
You can’t perform that action at this time.
0 commit comments