足球盘口软件
当前位置: 足球盘口软件 > 前端 >
JS建造者模式基本用法实例分析,js简单工厂模式用法实例

js简单工厂模式用法实例

   本文实例讲述了js简单工厂模式用法。分享给大家供大家参考。具体实现方法如下:

  ?

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

<!DOCTYPE html>

<html>

<head>

<title>简单工厂模式</title>

</head>

<body>

<script>

//简单工厂模式

var BicycleShop = function(){};

BicycleShop.prototype ={

sellBicycle : function(model){

var bicycle = null;

switch(model){

case 'The Speedster':

bicycle = new Speedster();

break;

case 'The lowride':

bicycle = new Lowride();

break;

case 'The Comfort Cruise':

bicycle = new ComfortCruise();

break;

};

Interface.ensureImplements(bicycle,Bicycle);

bicycle.assemble();

bicycle.wash();

return bicycle;

}

};

var AcmeBicycleShop = function(){};

extent(AcmeBicycleShop, BicycleShop);

AcmeBicycleShop.prototype.createBicycle = function(model){

var bicycle = null;

switch(model){

case 'The speedster':

bicycle = new AcmeSpeedster();

break;

case 'The Lowrider':

bicycle = new AcmeLowrider();

break;

case 'The Flatlander':

bicycle = new AcmeFlatlander();

break;

case 'The Comfort Cruiser':

default :

bicycle = new AcmeComfortCruiser();

};

Interface.ensureImplements(bicycle,Bicycle);

return bicycle;

};

//工厂模式适用与一个 fn 根据参数不同,创建不同的对象

</script>

</body>

</html>

  希望本文所述对大家的javascript程序设计有所帮助。

本文实例讲述了js简单工厂模式用法。分享给大家供大家参考。具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1...

本文实例讲述了js简单工厂模式用法。分享给大家供大家参考。具体实现方法如下:

JS建造者模式基本用法实例分析,js建造实例分析

本文实例讲述了JS建造者模式基本用法。分享给大家供大家参考。具体实现方法如下:

function getBeerById( id, callback){
  _request('GET','URL'+id,function(res){
   callback(res.responseText)
  });
};
function getBeerByIdBridge(){
  getBeerById(id,function(res){
   alert(res.toString());
  });
  //doAnothering;
};
var el = document.querySelector('#test');
el.addEventListener('click',getBeerByIdBrige,false);

所谓的建造者模式跟桥接模式一样好像,就是常见的回调,让思路更加清晰一点点

希望本文所述对大家的javascript程序设计有所帮助。

本文实例讲述了JS建造者模式基本用法。分享给大家供大家参考。具体实现方法如下: f...

简单工厂模式 //&#31616;&#21333;&#24037;&#21378;&#27169;&#24335; var BicycleShop = function(){}; BicycleShop.prototype ={ sellBicycle : function{ var bicycle = null; switch{ case 'The Speedster': bicycle = new Speedster(); break; case 'The lowride': bicycle = new Lowride(); break; case 'The Comfort Cruise': bicycle = new ComfortCruise(); break; }; Interface.ensureImplements; bicycle.assemble; return bicycle; } }; var AcmeBicycleShop = function(){}; extent(AcmeBicycleShop, BicycleShop); AcmeBicycleShop.prototype.createBicycle = function{ var bicycle = null; switch{ case 'The speedster': bicycle = new AcmeSpeedster(); break; case 'The Lowrider': bicycle = new AcmeLowrider(); break; case 'The Flatlander': bicycle = new AcmeFlatlander(); break; case 'The Comfort Cruiser': default : bicycle = new AcmeComfortCruiser(); }; Interface.ensureImplements; return bicycle; }; //&#24037;&#21378;&#27169;&#24335;&#36866;&#29992;&#19982;&#19968;&#20010; fn &#26681;&#25454;&#21442;&#25968;&#19981;&#21516;&#65292;&#21019;&#24314;&#19981;&#21516;&#30340;&#23545;&#35937;

希望本文所述对大家的javascript程序设计有所帮助。

返回顶部