Last active
July 25, 2016 15:08
-
-
Save winwu/09f5a22c2cec4c2f46e7be4bdbd7f5b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* TypeScript 可以使用 ES6 的 class 語法 | |
* 但 TypeScript 還可以額外使用靜態型別的那種修飾字: | |
* 如 public, protected, private | |
*/ | |
class Employee { | |
// name is public! | |
public name: string; | |
// manager is private, cannot be access from outside | |
private manager: string; | |
public constructor(theName: string, theManager: string) { | |
this.name = theName; | |
this.manager = theManager; | |
} | |
} | |
// get "Win Wu" | |
alert(new Employee("Win Wu", "Max").name); | |
/* get error: | |
* Property 'manager' is | |
* private and only accessible within class 'Employee'. | |
*/ | |
// alert(new Employee("Win Wu", "Max").manager); |
Author
winwu
commented
Jul 25, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment