發表文章

目前顯示的是 6月, 2013的文章

Web Components

圖片
今天想要跟大家聊聊 Web Components 這個新玩具,說是新玩具,其實這個概念已經發展有段時間了,尤其筆者本身是玩 Flash 技術出身的,發現 Web Components 跟 Flex Component 差不多,所以就來分享一些心得。 Web Components 是什麼? 簡單來講就是你可以客制化 HTML <tag>。 <my-component></my-component> 由 W3C 提出: The component model for the Web. When used in combination, Web Components enable Web application authors to define widgets with a level of visual richness and interactivity not possible with CSS alone, and ease of composition and reuse not possible with script libraries today. 使用 Web Components 有什麼好處? 鉴于许多Web框架通过暴露JavaScript API来构建用户界面,而构建用户界面实际上就是生成一堆div和spans标记,Web 组件是原生浏览器的解决方案因此不依赖于一个完整的框架。因此,与现在的一般依赖某个Javscript框架的HTML组件相比,Web组件希望能减少碎片。 最近新起許多 MDV (Model-driven-view) 這類 template 和 data binding 開發方式的框架 (backbone, angular, ember..), 那 Web Components 跟這些框架有什麼不同呢? 基本上就是希望藉由規格標準化,讓 Web application 的開發方式與架構更清晰。 Web Components 的瀏覽器支援情況? 尽管Web组件是一项有趣的新技术,但在浏览器们都支持它们(并且大部分用户都开始使用这些浏览器们)之前,其中的大部分功能还派不上用场。解决这个问题的一种方法是使用polyfills。 很遺憾,目前的瀏覽器普遍都還不支