自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

再談webOS開(kāi)發(fā)Enyo基礎(chǔ)控件

移動(dòng)開(kāi)發(fā)
這篇文檔中,我們?cè)僭敿?xì)的研究一下kinds, components和controls–這是我們?cè)谥v解webOS開(kāi)發(fā)的Enyo基礎(chǔ)中涉及到的三個(gè)基本的概念。

Kinds

在Enyo中,幾乎所有的代碼都放在叫做kind的對(duì)象prototype中。 kind是用enyo.kind工廠方法創(chuàng)建的constructor。

Enyo中的kind與Java或C++中的class類(lèi)似。例如,kinds通過(guò)子kinds繼承superkinds的屬性和方法的方式,提供了一種標(biāo)準(zhǔn)的實(shí)現(xiàn)繼承的機(jī)制。

這里是一個(gè)kinds的例子,它在二維和三維空間中表示一個(gè)點(diǎn). 注意第二個(gè)kind (Point3D)繼承自***個(gè)kind(Point):

  1. enyo.kind({ 
  2.  
  3. name: "Point", 
  4.  
  5. x: 0, 
  6.  
  7. y: 0, 
  8.  
  9. constructor: function(x, y) { 
  10.  
  11. this.x = x; 
  12.  
  13. this.y = y; 
  14.  
  15. }, 
  16.  
  17. translate: function(dx, dy) { 
  18.  
  19. this.x += dx; 
  20.  
  21. this.y += dy; 
  22.  
  23. }, 
  24.  
  25. toString: function() { 
  26.  
  27. return this.x + ", " + this.y; 
  28.  
  29.  
  30. }); 
  31.  
  32.   

 

  1. enyo.kind({ 
  2.  
  3. name: "Point3D", 
  4.  
  5. kind: "Point", 
  6.  
  7. z: 0, 
  8.  
  9. constructor: function(x, y, z) { 
  10.  
  11. this.inherited(arguments); 
  12.  
  13. this.z = z; 
  14.  
  15. }, 
  16.  
  17. translate: function(dx, dy, dz) { 
  18.  
  19. this.inherited(arguments); 
  20.  
  21. this.z += dz; 
  22.  
  23. }, 
  24.  
  25. toString: function() { 
  26.  
  27. return this.inherited(arguments) + ", " + this.z; 
  28.  
  29.  
  30. }); 
  31.  
  32. p = new Point3D(1, 1, 1); 

Components

Component對(duì)象是Enyo的基礎(chǔ)構(gòu)建塊。所有的Components擁有同樣的特性,不同的Components可以按一種標(biāo)準(zhǔn)的方式協(xié)同工作。例如,所有的components有一個(gè)name屬性(字符串)。一個(gè)組件component可能會(huì)創(chuàng)建其它的components,這被稱(chēng)為擁有。每個(gè)component維護(hù)著一組它自己擁有的component,并負(fù)責(zé)這些component的生命周期。

下面是兩個(gè)component的kind定義。運(yùn)行時(shí),一個(gè)SimulatedMessage對(duì)象創(chuàng)建(并擁有)一個(gè)RandomizedTimer對(duì)象,RandomizedTimer可以隨機(jī)間隔的模擬發(fā)送服務(wù)消息:

  1. enyo.kind({ 
  2.  
  3. name: "RandomizedTimer", 
  4.  
  5. kind: enyo.Component, 
  6.  
  7. baseInterval: 100, 
  8.  
  9. percentTrigger: 50, 
  10.  
  11. events: { 
  12.  
  13. onTriggered: "" 
  14.  
  15. }, 
  16.  
  17. create: function() { 
  18.  
  19. this.inherited(arguments); 
  20.  
  21. this.job = window.setInterval(enyo.hitch(this, "timer"), this.baseInterval); 
  22.  
  23. }, 
  24.  
  25. destroy: function() { 
  26.  
  27. window.clearInterval(this.job); 
  28.  
  29. }, 
  30.  
  31. timer: function() { 
  32.  
  33. if (Math.random() < this.percentTrigger * 0.01) { 
  34.  
  35. this.doTriggered(); 
  36.  
  37.  
  38.  
  39. }); 
  40.  
  41.   

 

  1. enyo.kind({ 
  2.  
  3. name: "SimulatedMessage", 
  4.  
  5. kind: enyo.Component, 
  6.  
  7. components: [ 
  8.  
  9. {name: "timer", kind: RandomizedTimer, percentTrigger: 10, 
  10.  
  11. onTriggered: "timerTriggered"} 
  12.  
  13. ], 
  14.  
  15. timerTriggered: function() { 
  16.  
  17. this.log("Simulated Service Message Occurred"); 
  18.  
  19.  
  20. }); 

Controls

Control對(duì)象是一個(gè)控制DOM節(jié)點(diǎn)的component(i.e., 一個(gè)界面中的元素)。Controls通常是可見(jiàn)的,用戶(hù)直接與它們交互。例如按鈕或者輸入框都是controls,但在Enyo中,一個(gè)control可能會(huì)變得和整個(gè)程序一樣復(fù)雜。

在下面的例子中我們定義了一個(gè)Circle control并把它放在TrafficLight control中:

  1. enyo.kind({ 
  2.  
  3. name: "Circle", 
  4.  
  5. kind: "Control", 
  6.  
  7. published: { 
  8.  
  9. color: "magenta", 
  10.  
  11. bgColor: "black" 
  12.  
  13. }, 
  14.  
  15. content: "Hi", 
  16.  
  17. style: "padding: 2px 6px; border: 3px solid; border-radius: 20px; 
  18.  
  19. cursor: pointer;", 
  20.  
  21. create: function() { 
  22.  
  23. this.inherited(arguments); 
  24.  
  25. this.colorChanged(); 
  26.  
  27. }, 
  28.  
  29. colorChanged: function() { 
  30.  
  31. this.applyStyle("border-color", this.color); 
  32.  
  33. }, 
  34.  
  35. bgColorChanged: function() { 
  36.  
  37. this.applyStyle("background-color", this.bgColor); 
  38.  
  39. }, 
  40.  
  41. mousedown: function() { 
  42.  
  43. this.applyStyle("background-color", "white"); 
  44.  
  45. }, 
  46.  
  47. mouseup: function() { 
  48.  
  49. this.applyStyle("background-color", "black"); 
  50.  
  51.  
  52. }); 
  1. enyo.kind({ 
  2.  
  3. name: "TrafficLight", 
  4.  
  5. kind: "Control", 
  6.  
  7. style: "position: absolute; padding: 4px; border: 1px solid black; 
  8.  
  9. background-color: silver;"}, 
  10.  
  11. components: [ 
  12.  
  13. {kind: "Circle", color: "red", onclick: "circleClick"}, 
  14.  
  15. {kind: "Circle", color: "yellow", onclick: "circleClick"}, 
  16.  
  17. {kind: "Circle", color: "green", onclick: "circleClick"} 
  18.  
  19. ], 
  20.  
  21. circleClick: function(inSender) { 
  22.  
  23. var lights = {red: "tomato", yellow: "#FFFF80", green: "lightgreen"}; 
  24.  
  25. if (this.lastCircle) { 
  26.  
  27. this.lastCircle.setBgColor("black"); 
  28.  
  29.  
  30. this.lastCircle.setBgColor(lights[inSender.color]); 
  31.  
  32. this.lastCircle = inSender
  33.  
  34.  
  35. }); 
責(zé)任編輯:佚名 來(lái)源: baiyuxiong
相關(guān)推薦

2011-07-04 10:55:10

EnyowebOS 3.0 S

2011-07-18 10:57:58

webOSEnyo系統(tǒng)服務(wù)

2010-11-23 08:39:41

EnyowebOS 2.0WebOS

2011-07-01 11:02:30

EnyowebOShello world

2011-07-01 10:52:59

EnyowebOS 3.0 S

2012-05-26 23:32:54

webOS

2012-05-27 08:05:00

惠普webOS集體離職

2010-06-17 16:27:26

WAP協(xié)議

2009-08-06 18:18:27

ASP.NET控件開(kāi)發(fā)ASP.NET復(fù)合控件

2009-08-07 10:34:56

ASP.NET控件開(kāi)發(fā)

2009-08-07 13:31:41

ASP.NET控件開(kāi)發(fā)

2011-04-06 15:55:50

開(kāi)發(fā)webOS程序webOS

2011-04-13 15:31:53

webOS 2.0開(kāi)發(fā)者大會(huì)webOS

2009-08-06 09:18:01

ASP.NET自定義控ASP.NET控件開(kāi)發(fā)

2010-03-29 14:09:34

2009-04-03 11:12:43

PalmwebOS開(kāi)發(fā)

2011-09-05 14:21:29

webOS

2012-02-08 09:49:02

惠普webOS開(kāi)源

2009-08-06 18:32:00

ASP.NET控件開(kāi)發(fā)ASP.NET復(fù)合控件

2009-08-07 14:42:02

ASP.NET控件開(kāi)發(fā)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)