{"id":3748,"date":"2016-04-18T01:29:43","date_gmt":"2016-04-18T01:29:43","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3748"},"modified":"2016-04-18T01:29:43","modified_gmt":"2016-04-18T01:29:43","slug":"typescript-class-example","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/typescript-class-example\/","title":{"rendered":"TypeScript class example"},"content":{"rendered":"<p>One of the nice features of Typescript is that you can create classes. Now that ES6 also has this, it&#8217;s a little less impressive than it used to be, but lets take a look at what it lets use do:<\/p>\n<pre lang=\"javascript\">\nclass Dialog {\n    title: String = \"Test Title\";\n    message: String;\n   \n    constructor(message: String) {\n        this.message = message;    \n    }\n     \n    render() {\n        console.log(this.title);\n        console.log(this.message); \n    }\n}\n\nlet d: Dialog = new Dialog(\"Test Message\");\n<\/pre>\n<p>Note that we have constructors, properties with types, and we can set default values for types. You can use public\/private as well, but they are only enforced by the compiler.<\/p>\n<p>Here, you can see an example with inheritance:<\/p>\n<pre lang=\"javascript\">\nclass AlertDialog extends Dialog {\n     render() {\n         console.log(\"Alert\"); \n     }    \n}\n\nlet ad: Dialog = new AlertDialog(\"alert message\");\nad.render();\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Classes and inheritance in typescript<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[302,557],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3748"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3748"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3748\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}