-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path多态.js
More file actions
71 lines (50 loc) · 1.13 KB
/
多态.js
File metadata and controls
71 lines (50 loc) · 1.13 KB
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
// var makeSound = function( animal ) {
// if ( animal instanceof Duck ) {
// console.log( '嘎嘎嘎' );
// }else if ( animal instanceof Chicken ) {
// console.log( '咯咯咯' );
// }
// };
// var Duck = function() {};
// var Chicken = function() {};
// makeSound( new Duck() );
// makeSound( new Chicken() );
var makeSound = function( animal ) {
animal.sound();
};
var Duck = function(){};
Duck.prototype.sound = function() {
console.log( '嘎嘎嘎' );
};
var Chicken = function() {};
Chicken.prototype.sound = function() {
console.log( '咯咯咯' );
};
makeSound( new Duck() );
makeSound( new Chicken() );
var googleMap = {
show: function() {
console.log( '开始渲染google地图' );
}
};
var baiduMap = {
show: function() {
console.log( '开始渲染Baidu地图' );
}
};
var sosoMap = {
show: function() {
console.log( '开始渲染Soso地图' );
}
};
// var renderMap = function() {
// googleMap.show();
// };
var renderMap = function( map ) {
if ( map.show instanceof Function ) {
map.show();
}
};
renderMap( googleMap );
renderMap( baiduMap );
renderMap( sosoMap );