Canvas 链式操作

canvas有个非常麻烦的地方就是不支持链式操作,导致书写极其繁琐,刚刚学习了canvas的链式操作。

下面是代码

改进之后的写法,犀利得多啊!

1.canvas = document.querySelector('#canvas')
2.
3.class C2D
4. (canvas) ->
5. @context = canvas.getContext \2d
6. for let prop of @context
7. @[prop] = ->
8. if typeof @context[prop] is "function"
9. return @context[prop].apply @context, & or this
10. @context[prop] = Array.prototype.join.call &
11. this
12. this
13.
14.cc = new C2D canvas
15.cc.beginPath!
16. .arc 50, 50, 20, Math.PI * 2, false
17. .fillStyle("red")
18. .fill!
19. .stroke!
20. .beginPath!
21. .moveTo 100, 100
22. .lineTo 200, 200
23. .strokeStyle "lawngreen"
24. .lineWidth 10
25. .stroke!
26.
 
 

最新文章

  1. dijkstra 最短路算法
  2. Java类型相互转换byte[]类型,blob类型
  3. Diving Into Lync Client Logins
  4. 【转】TCP三次握手过程
  5. JAVA 年轻代收集器 第九节
  6. GCD实现倒计时
  7. 逆向集录_00_不同程序OEP特征总结
  8. 深入理解SpringBoot之装配条件
  9. 微信小程序 组件 Demo
  10. LR参数化取值规则总结
  11. C语言 · 单词数统计
  12. python 全栈开发,Day82(点赞和踩灭,用户评论)
  13. vue给元素动态添加class
  14. html随笔CSS(*^__^*)
  15. Knockout学习,添加模板,事件,Mouseover,mouseout
  16. 基于Python自动上传包到nexus仓库
  17. 企业搜索引擎开发之连接器connector(二十一)
  18. Undirected Graphs
  19. Ubuntu/Debian下编译PC版的ffmpeg
  20. 浅谈深度学习中的激活函数 - The Activation Function in Deep Learning

热门文章

  1. android 跨进程通讯 AIDL
  2. SIGGRAPH 2017:深度学习与计算机图形学的碰撞
  3. 将C4C Service Request中的summary和其他附件同步到ERP的Billing Request去
  4. 2018.2.25 关于JavaScript
  5. java sql database相关收集
  6. eclipse报错GC overhead limit exceed,卡顿
  7. javaweb基础(6)_servlet配置参数
  8. iOS 通过storyboard设置UIView或者其他layer图层的圆角
  9. 吐槽在cocos2dx游戏接入腾讯信鸽的坑
  10. cesium底图加载底图切换 基于天地图服务