{"id":367,"date":"2020-07-27T09:07:05","date_gmt":"2020-07-27T00:07:05","guid":{"rendered":"https:\/\/blog.wsd.sh\/?p=367"},"modified":"2020-07-27T09:07:32","modified_gmt":"2020-07-27T00:07:32","slug":"16-17-javascript-%e5%a4%89%e6%9b%b4%e3%80%80%e5%ae%8c%e6%88%90","status":"publish","type":"post","link":"https:\/\/blog.wsd.sh\/?p=367","title":{"rendered":"16->17 JavaScript \u5909\u66f4\u3000\u5b8c\u6210"},"content":{"rendered":"<p>1. \/\/ main.js<br \/>\nbrfore:<\/p>\n<pre>\r\n                       root.setBgColor(root.bgColor);\r\n<\/pre>\n<p>after:<\/p>\n<pre>\r\n\r\n<\/pre>\n<p>2. \/\/ canvas.js<br \/>\n2.1  \u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0<br \/>\nbrfore:<\/p>\n<pre>\r\nfunction rootCreate () {\r\n<\/pre>\n<p>after:<\/p>\n<pre>\r\nfunction rootCreate () {\r\n        \/\/ context\r\n        this.ctx = null;\r\n        this.canvas = null;\r\n        this.cnvWidth = 500;\r\n        this.cnvHeight = 500;\r\n    \/\/ \u5909\u6570\u5ba3\u8a00\r\n\r\n        this.bgColor = \"transparent\";\r\n\r\n        this.getCanvas = () => {\r\n                return this.canvas;\r\n        }\r\n        this.setCanvas = (canvas) => {\r\n                this.canvas = canvas;\r\n        }\r\n\r\n        this.getCtx = () => {\r\n                return this.ctx;\r\n        }\r\n        this.setCtx = (ctx) => {\r\n                this.ctx = ctx;\r\n        }\r\n\r\n        this.getCnvWidth = () => {\r\n                return this.cnvWidth;\r\n        }\r\n\r\n        this.getCnvHeight = () => {\r\n                return this.cnvHeight;\r\n        }\r\n\r\n        this.getCnvColor = () => {\r\n                return this.cnvColor;\r\n        };\r\n\r\n\r\n        this.getCnvBold = () => {\r\n                return this.cnvBold;\r\n        };\r\n\r\n        this.getBgColor = () => {\r\n                return this.bgColor;\r\n        };\r\n\r\n\r\n<\/pre>\n<p>2.2  \u30de\u30a6\u30b9\u62bc\u4e0b\u958b\u59cb<br \/>\nbrfore:<\/p>\n<pre>\r\n                \/\/ \u30de\u30a6\u30b9\u62bc\u4e0b\u958b\u59cb\r\n                        this.drawStart(e.offsetX, e.offsetY, this.cnvBold, this.cnvColor);\r\n<\/pre>\n<p>after:<\/p>\n<pre>\r\n                \/\/ \u30de\u30a6\u30b9\u62bc\u4e0b\u958b\u59cb\r\n                        this.drawStart(e.offsetX, e.offsetY, this.getCnvBold(), this.getCnvColor());\r\n<\/pre>\n<p>2.3  \u30de\u30a6\u30b9\u62bc\u4e0b\u7d42\u4e86<br \/>\nbrfore:<\/p>\n<pre>\r\n                \/\/ \u30de\u30a6\u30b9\u62bc\u4e0b\u7d42\u4e86\r\n                        this.canvas.removeEventListener(\"mousemove\" , this.mouseMove, false);\r\n<\/pre>\n<p>after:<\/p>\n<pre>\r\n                \/\/ \u30de\u30a6\u30b9\u62bc\u4e0b\u7d42\u4e86\r\n                        let canvas = this.getCanvas();\r\n                        canvas.removeEventListener(\"mousemove\" , this.mouseMove, false);\r\n<\/pre>\n<p>2.4  \/\/ canvas\u4e0a\u3067\u306e\u30a4\u30d9\u30f3\u30c8<br \/>\nbrfore:<\/p>\n<pre>\r\n                \/\/ canvas\u4e0a\u3067\u306e\u30a4\u30d9\u30f3\u30c8\r\n                this.draw(e.offsetX, e.offsetY, this.cnvBold, this.cnvColor);\r\n<\/pre>\n<p>after:<\/p>\n<pre>\r\n                \/\/ canvas\u4e0a\u3067\u306e\u30a4\u30d9\u30f3\u30c8\r\n                this.draw(e.offsetX, e.offsetY, this.getCnvBold(), this.getCnvColor());\r\n<\/pre>\n<p>2.5  canvas\u306e\u80cc\u666f\u8272\u3092\u8a2d\u5b9a(\u6307\u5b9a\u304c\u306a\u3044\u5834\u5408\u306bjpeg\u4fdd\u5b58\u3059\u308b\u3068\u80cc\u666f\u304c\u9ed2\u306b\u306a\u308b)<br \/>\nbrfore:<\/p>\n<pre>\r\n        \/\/ canvas\u306e\u80cc\u666f\u8272\u3092\u8a2d\u5b9a(\u6307\u5b9a\u304c\u306a\u3044\u5834\u5408\u306bjpeg\u4fdd\u5b58\u3059\u308b\u3068\u80cc\u666f\u304c\u9ed2\u306b\u306a\u308b)\r\n\r\n                let ctx = this.getCtx();\r\n\r\n                ctx.fillStyle = bgColor;\r\n                ctx.fillRect(0, 0, this.getCnvWidth(), this.getCnvHeight());\r\n<\/pre>\n<p>after:<\/p>\n<pre>\r\n        \/\/ canvas\u306e\u80cc\u666f\u8272\u3092\u8a2d\u5b9a(\u6307\u5b9a\u304c\u306a\u3044\u5834\u5408\u306bjpeg\u4fdd\u5b58\u3059\u308b\u3068\u80cc\u666f\u304c\u9ed2\u306b\u306a\u308b)\r\n\r\n                this.ctx.fillStyle = bgColor;\r\n                this.ctx.fillRect(0, 0, this.cnvWidth, this.cnvHeight);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. \/\/ main.js brfore: root.setBgColor(root.bgColor); after: 2. \/\/ canvas.js 2.1 \u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30d5\u30a1\u30f3\u30af\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0 brfore:&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/367"}],"collection":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=367"}],"version-history":[{"count":1,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":368,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/367\/revisions\/368"}],"wp:attachment":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}