Commit 624cc5a traed
committed
1 parent 91da65d commit 624cc5a Copy full SHA for 624cc5a
File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -10,16 +10,26 @@ var myObject = {
10
10
return obj ;
11
11
} ,
12
12
'call' : function ( funcName , params ) {
13
+ var visited = [ ] ;
14
+ return this . findFunc ( funcName , params , visited ) ;
15
+ } ,
16
+ 'findFunc' : function ( funcName , params , visited ) {
17
+ visited . push ( this ) ;
13
18
if ( this . hasOwnProperty ( funcName ) ) {
14
19
return this [ funcName ] ( params ) ;
15
20
}
16
21
var result ;
17
22
this . prototypes . forEach (
18
23
function ( obj ) {
19
- var call = obj . call ( funcName , params )
20
- if ( call != undefined && result === undefined ) {
21
- result = call ;
24
+ if ( visited . indexOf ( obj ) == - 1 ) {
25
+ var call = obj . findFunc ( funcName , params , visited )
26
+ if ( call != undefined && result === undefined ) {
27
+ result = call ;
28
+ return ;
29
+ }
22
30
}
31
+ else
32
+ console . log ( "WARNING: Circular inheritance detected!" ) ;
23
33
}
24
34
) ;
25
35
return result ;
37
47
console . log ( obj3 . call ( 'func' , 'hello' ) ) ;
38
48
}
39
49
catch ( err ) {
40
- console . log ( "Params must be Array" )
50
+ console . log ( err )
41
51
}
You can’t perform that action at this time.
0 commit comments